Using jquery to get all checked checkboxes with a certain class name

leora picture leora · Mar 27, 2011 · Viewed 394.5k times · Source

I know I can get all checked checkboxes on a page using this:

$('input[type=checkbox]').each(function () {
    var sThisVal = (this.checked ? $(this).val() : "");
});

But I am now using this on a page that has some other checkboxes that I don't want to include. How would I change the above code to only look at checked checkboxes that have a certain class on them?

Answer

Cokegod picture Cokegod · Mar 27, 2011

$('.theClass:checkbox:checked') will give you all the checked checkboxes with the class theClass.