I'll try and make this question simple. Can I assign a class to a series of different checkboxes, and use Jquery to do something when any one of those checkboxes is checked? Searching around on the internet I have found documentation on grabbing the name: $('input[name=foo]').is(':checked')
but when I swap out the name attribute for the class attr, it won't work! How can I set an event to occur if any of the checkboxes with this certain class is checked? Please help me out! Thanks
views:
31answers:
2
+3
A:
Use hasClass
to test whether or not a particular element has been assigned a certain class e.g.:
$(document).ready(function() {
$("input[name=something]:checkbox").click(function() {
if($(this).is(":checked") && $(this).hasClass("foo")) {
// the checkbox has been checked and has a class of foo
}
});
});
karim79
2010-05-14 15:49:46
A:
You can get the status of all the checkbox at a single go by putting same name to all the checkboxes.
Kangkan
2010-05-14 15:51:37