The easiest way to do such things is to specify the value of your flags as identifiers for your strings. You can do this easily with PHP or HTML. So, for example, if you have a checkbox with a single value, make sure that its sibling table cell has a value as an identifier:
<tr> <td> <input type="checkbox" name="name" class="click_me" value="2"> </td> <td id="2"> 2 </td> <td id="5"> 5 </td> </tr>
When you click on the check box, collect the values ββin an array:
$('.click_me').click(function(){ var thisArray = new Array(); $(this).parent('td').siblings('td').each(function(){ thisArray[] = $(this).attr('id'); }); });
Now we have an array filled with all these string values. Now we need to find all the values ββof the other lines:
var otherArray = new Array(); $('.click_me:selected').not(this).each(function(){ otherArray[] = $(this).parent().siblings('td').each(function(){ otherArray[] = $(this).attr('id'); }); });
Now we have two arrays: one with the values ββof the column that you just selected, and the rest are all the other existing ones. Now we need to compare them. If any values ββmatch in two arrays, we can do something like adding a class:
for (var i = 0; thisArray[i]; i++) { if (jQuery.inArray(thisArray[i],otherArray)) { $(this).parent('tr').addClass('selected'); } }
If a value exists in both thisArray and otherArray , the parent element for the input you click will have an added class. You can use CSS to change the style for this row of the table, or even to select table cells in that row.
source share