views:

31

answers:

2

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

+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
        }
    });
});

Try a demo here.

karim79
A: 

You can get the status of all the checkbox at a single go by putting same name to all the checkboxes.

Kangkan