Add a class to all selected cells

Tags: #<Tag:0x00007efc83415088> #<Tag:0x00007efc8342e9c0>

When clicking an button (outside of the table) I’d like the selected cells to change background colors. I previously was using this:

$('.handsontable td.current, .handsontable td.highlight').css('background-color', color);

This isn’t the correct method, as it is reset from other operations. What is the best way to either set a class, or apply the styles directly to the td?

I’ve also tried hot.getSelected() and hot.getSelectedRange but I don’t know how to use this data to apply a class against, as it outputs indices.

Hi @jbird1111

Thank you for contacting us. Here we have most recent example of suggested implementation of this functionality: https://jsfiddle.net/handsoncode/vz37t092/

1 Like