How to count check-boxes using jQuery? How to count check-boxes using jQuery? jquery jquery

How to count check-boxes using jQuery?


You could do:

var numberOfChecked = $('input:checkbox:checked').length;var totalCheckboxes = $('input:checkbox').length;var numberNotChecked = totalCheckboxes - numberOfChecked;

EDIT

Or even simple

var numberNotChecked = $('input:checkbox:not(":checked")').length;


Assume that you have a tr row with multiple checkboxes in it, and you want to count only if the first checkbox is checked.

You can do that by giving a class to the first checkbox

For example class='mycxk' and you can count that using the filter, like this

$('.mycxk').filter(':checked').length


The following code worked for me.

$('input[name="chkGender[]"]:checked').length;