.
This will lead to complex events and can lead to serious browser performance problems if the user clicks the table many times.
Simply put, click on the table 4 times and each time the checkbox changes, it calls 4 change handlers
An easy way to highlight rows is to use the number of checked flags per row to determine the state of the class.
$('table.highlight_row input:checkbox').change(function(){
var $row = $(this).closest('tr'),
hasChecked = $row.find(':checkbox:checked').length;
$row.toggleClass('selected', hasChecked);
});
Cell selection is even easier ... just switch the class to the parent cell based on checked state
$('table.highlight_td input:checkbox').change(function(){
$(this).parent().toggleClass('selected', this.checked);
});
source
share