Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery select (each) all checked checkboxes?

Tags:

jquery

css

Can anyone help with the following, it doesn't return any checked checkboxes.. Am i doing somethign wrong?

I have

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

here is part of my html ( i have a number of them all 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>
like image 746
mark smith Avatar asked Dec 01 '22 07:12

mark smith


1 Answers

Just do:

$(":checked")...

for checked checkboxes. Also you have an extraneous space in your expression before ".type-element". If you want to make sure the checked checkboxes have that class use:

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

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

So the end result is:

$(":checked.type-element").each(
  function(index) {
    alert('checked' + index);
  }
);
like image 190
cletus Avatar answered Dec 03 '22 22:12

cletus