hiii,
I want to detect how many checkboxes are checked in given list checkboxes.
One method that I know is to check it by looping through the list and check one by one if it is checked
$('.chkBoxList').each(function() {
if($(this).is(':checked'))
{
// do something
}
But I feel it is quite inefficient method. As if there are hundreds/thousands of checkboxes and only few of them are checked, it will still loop through all the checkboxes.
Is there any other way to improve it. I would be grateful if anyone can suggest an efficient alternative to it. Please guide me & suggest appropriate solution with pros & cons.
Thanks in advance.
This will get all checked inputs (assuming there’s no any radios) inside element with class
chkBoxListandlengthproperty will be the count of them:If your checkboxes have
chkBoxListclass use this: