I have a table with multiple rows, where I have styled each odd row in one shade of gray and the even rows in slightly different shades to make it easier to read.
When clicking on a row, I am currently highlighting it with a different color to indicate which record has been selected. However, I'm not sure how to revert the color back to its original when selecting a different row.
Currently, I find myself having to set all the rows back to their alternate gray colors as a workaround, and then apply the new highlighted color to the selected row.
I was hoping to find a better way to achieve this effect without resorting to such workarounds.
$(document).on("click","#div2 tr#abc", function(event) {
barcode = $(this).data('barcode');
$('tr:odd[id="abc"]').css('backgroundColor', '#FAFAFA');
$('tr:even[id="abc"]').css('backgroundColor', '#F2F2F2');
$(this).css('backgroundColor','#FFD6F5');
});