Add a class to all selected cells

Tags: #<Tag:0x00007f136010e828> #<Tag:0x00007f136010e5f8>

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