I previously worked on a page using jquery where I needed to select checkboxes in a table based on some data attributes, I.e any row where a checkbox is selected will lead to all the other checkboxes being disabled if their data attributes do not match the given criteria.
There is now another requirement to the above case where I'd like to only highlight the first row of the first checkbox that is checked at any given time.
Here is the jquery snippet
$(function() {
$(".my-check").each(function(e, elem) {
$(elem).on("change", function() {
var num = $(this).data("number");
var co = $(this).data("code");
if ($(this).eq(0).is(':checked')) {
$(this).closest('.row').addClass('highlight');
$('.my-check:not([data-number=' + num + '])').attr('disabled', true);
$('.my-check:not([data-code=' + co + '])').attr('disabled', true);
} else {
if (!$('.my-check[data-number=' + num + ']:checked').length) {
$(this).closest('.row').removeClass('highlight');
$(".my-check").not($(this)).attr('disabled', false);
}
}
});
})
});
And the sample working code Here: Sample code here
The highlight is working (Well almost) but not quite so . I'd like to be able to only highlight one row at a time , where a checkbox is checked