Jquery get checked checkboxes

I am trying to get a list of checkboxes and a counter that is checked. I have it:

var obj = $(this).closest('li').find(':checkbox'); var childCount=$(obj).size(); var checkedCount=$(obj).(':checked').length; 

I get an error on checkedCount

??

+6
source share
2 answers

You need to use the filter() function:

  var obj = $(this).closest('li').find(':checkbox'); var childCount = obj.size(); var checkedCount = obj.filter(':checked').length; 

filter
Reduce the set of matched elements to those that match the selector or pass the function test.

Also, you do not need to wrap obj with $() , because it is already a jQuery object.

+14
source

you have a typo .. you cannot do $ ('# foo'). () .. you need:

 $('#foo').filter(':checkbox') 

filter selector - http://api.jquery.com/filter

0
source

Source: https://habr.com/ru/post/887356/


All Articles