TheBoubou
TheBoubou

Reputation: 19903

Number of checkbox check for a specific class

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

Answers (6)

Mikeys4u
Mikeys4u

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

Vpn_talent
Vpn_talent

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

kobe
kobe

Reputation: 15835

try this

made jsFiddle from other post code

http://jsfiddle.net/8n6Rp/

$(function(){
    alert( $(".myClassA:checkbox:checked").length );
});

Upvotes: 2

T1000
T1000

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

Edgar Villegas Alvarado
Edgar Villegas Alvarado

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

Prakash
Prakash

Reputation: 6602

Try this :

$('input:checkbox.myClassA:checked').length

Upvotes: 9

Related Questions