I am using jQuery 1.4.3
I have several input that look like this:
<input type='checkbox' id='1' class='Product' comp='1'>
<input type='checkbox' id='2' class='Product' comp='1'>
<input type='checkbox' id='3' class='Product' comp='1'>
<input type='checkbox' id='4' class='Product' comp='2'>
<input type='checkbox' id='5' class='Product' comp='2'>
<input type='checkbox' id='6' class='Product' comp='2'>
If a box with the Product class is clicked I want to get its comp value and uncheck the other boxes that have a different comp value.
Normally, I would loop through and check each comp value and then uncheck where necessary, like this pseudo code:
ThisComp == 1 // comp value of checkbox that was just clicked
$(".Product").each(function() {
var Comp $(this).attr("comp");
if (ThisComp != Comp) {
// $(this).attr("checked", false);
}
});
I am wondering if there is a way to filter using the comp value in the selector, such as this pseudo code:
$(".Product comp=2").attr("checked", false);
The goal here is to uncheck any box that has a different comp value than the one clicked in an efficient way.
http://api.jquery.com/category/selectors/