Jquery select (each) all checked checkboxes?

Can anyone help with the following, it does not return any checked flags. Am I doing something wrong?

I have

$("input[type=checkbox][checked] .type-element").each( function(index) { alert('checked' + index); } ); 

here is part of my html (I have all of them as type-container)

  <div id="type-1" class="type-container"> <div class="type-description"> test </div> <input id="11" class="type-element" type="checkbox"/> </div> 
+4
source share
1 answer

Just do:

 $(":checked")... 

for checked flags. In addition, you have the outer space in your expression before the ".type-element". If you want to make sure that checked flags have this class, use:

 $(":checked.type-element")... 

not ":checked .type-element" (note the space).

So the end result:

 $(":checked.type-element").each( function(index) { alert('checked' + index); } ); 
+19
source

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


All Articles