tags:

views:

527

answers:

1

Hi there,

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>
+6  A: 

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);
  }
);
cletus
Thanks it worked! just for testing - i tried using (moving space) $("input[type=checkbox][checked].type-element") and it didn't work... I though input[type=.... was teh recommended way with jquery 1.3? ... or is :checked?
mark smith
$("input[type='checkbox']:checked")
glavić
thanks a lot for the comment
mark smith