Reputation: 19903
I have on a page some checkbox some of these checkbox have "myClassA" or "myClassB".
I'd like get the number fo checkbox checked but only for the checkbox with class = "myClassA"
Thanks,
Upvotes: 2
Views: 9091
Reputation: 1552
You can use the following solution to solve your problem:
var mychecked = $('.selectsms:checked').length
if (mychecked==0) {
alert("Please choose at least one checkbox");
}
Upvotes: 1
Reputation: 1436
if you have checkbox in multiple classes. and want to find only a specific class's checked box count then this will be definitely helpful.
var numberOfChecked = $(divId).find(".checkbutton").find(":checkbox:checked").length;
alert(numberOfChecked);
Upvotes: 0
Reputation: 15835
try this
made jsFiddle from other post code
$(function(){
alert( $(".myClassA:checkbox:checked").length );
});
Upvotes: 2
Reputation: 2941
<input type='checkbox' checked='checked' class='A' />
<input type='checkbox' class='A' />
<input type='checkbox' checked='checked' class='A' />
<input type='checkbox' checked='checked' class='A' />
<input type='checkbox' checked='checked' class='A' />
<input type='checkbox' checked='checked' class='B' />
<input type='checkbox' checked='checked' class='B' />
<input type='checkbox' checked='checked' class='B' />
4 class="A" input boxes are checked
alert($('.A:checked').length)
Upvotes: 0
Reputation: 18344
With this:
var classAChecked = $(".myClassA:checkbox:checked").size();
The :checkbox
selector selects all checkboxes, while the :checked
filters only the checked ones.
Hope this helps
Upvotes: 0