JohnC
JohnC

Reputation: 21

Looping over child selectors

greetings, I have a div wrapped around a bunch of checkboxes on my form.

<div id="checker">
  <input type="checkbox" name="dynamic" id="dynamic" value="dynamic" />
  <input type="checkbox" name="dynamic" id="dynamic" value="dynamic" />
  <input type="checkbox" name="dynamic" id="dynamic" value="dynamic" />
</div>

... where "dynamic" (above) is coming from a database and I don't know the names or ids. These would be created in a loop of php code - not shown.

Using JQuery, how do I access these checkboxes, so I can loop over them? I'd like to do something like:

$('#checker').children('checkbox').each( function(){ .... });  

(I know that is wrong - it's just to show what I'm thinking).

Thoughts? Thanks JohnC

Upvotes: 0

Views: 104

Answers (5)

Egor4eg
Egor4eg

Reputation: 2708

$('#checker').children('input [type="checkbox"]').each(
  function(){ 
    .... 
  });

Upvotes: 0

Nick G
Nick G

Reputation: 960

Try this:

$('#checker input:checkbox').each(function(){
    //do stuff
});

Upvotes: 2

John Hartsock
John Hartsock

Reputation: 86902

If #checker is the id to your div then

$("div#checker input:checkbox").each(function () { ... });

Upvotes: 0

D. Patrick
D. Patrick

Reputation: 3022

$('#checker input:type="checkbox"').each(...);

Upvotes: 1

AndreKR
AndreKR

Reputation: 33697

$('#checker input:checkbox').each( function() { ... } );

Upvotes: 4

Related Questions