I have a table with checkboxes in the first column, and a "select all" checkbox in the header. When I check a checkbox, I need the row color to change.
var $tbl = $('#tbl');
var $bodychk = $tbl.find('tbody input:checkbox');
$(function () {
$bodychk.on('change', function () {
$(this).closest('tr').toggleClass('hilite');
});
$tbl.find('thead input:checkbox').change(function () {
var c = this.checked;
$bodychk.prop('checked', c);
});
});
- If you select the individual boxes, the row changes color
- If you click the "select all" box, it'll toggle the other checkboxes.
But I can't get both working together. See here
These questions come close but don't fully answer what might be wrong...
.trigger()but as the issue is only with adding/removing a class, your fiddle is much cleaner. cheers!