Reputation: 196499
i have jquery code that loop through all checkboxes.
$('input[type=checkbox]').each(function () {
I now need to make this code more restrictive because i now have other checkboxes on this page. how can i change this so it only loops through all checkboxes with a certain class name?
Upvotes: 0
Views: 510
Reputation: 6192
No need to include 'input' in the selector:
$(':checkbox.class')
Upvotes: 1
Reputation: 183
If you're just making a selection, does this really need to be in a loop?
This will return a jQuery object matching your criteria:
$('input.className[type=checkbox]')
if you need it in a loop:
$('input[type=checkbox]').each(function() {
if ($(this).hasClass('className')) {
// Do Stuff Here
}
});
Upvotes: 0