views:

36

answers:

5
$('#foo input');
$('#foo').find('input');

Both I believe get only the inputs straight descendant to #foo (ie. only the inputs nested immediately within foo). How can I get all the inputs, no matter how deeply nested in #foo?

Edit: Bah, this works. Sloppy me. Need coffee. Thank you all.

+3  A: 

No, #foo input should find all input descendants of #foo.

Read the documentation on CSS selectors for more information and options.

jtbandes
Accepting in 9 minutes.
randomguy
+1  A: 

Both of these get all descendant inputs.

If you wanted only immediate children, you would do:

$('#foo > input');
$('#foo').children('input');

Selectors:

Methods:

patrick dw
A: 

Your code does exactly what you want. It will match any INPUT element which is a child, grandchild, etc of #foo.

The way to get an element which is a direct child of foo would be

$("#foo>input");
slightlymore
A: 

No you are not right, at least

$('#foo input');

does the job - according to http://api.jquery.com/descendant-selector/ gives all the input descendats of #foo. It is very similar to css selectors.

gorn
A: 
$('#foo > input');
dejavu