views:

58

answers:

2

Hi,

I want to access a simple button in an unknown nested level of a container.

Using container.children('button') allows me to access buttons in the first level, i.e.:

<div>
 <button>test</button>
</div>

Trying to use the same with the following construct:

<div>
 <div>
  <button>test</button>
 </div>
</div>

.. fails, because the button is not a direct children. I could use element.children().children('button') but the depth of the button can change and this feels too strange.

I can also write my own function to iterate thru all children to find what I need, but I guess jQuery does already have selectors for this.

So the question is:

How can I access children in an unknown depth using jQuery selectors?

Thank you all in advance for your feedback!

+5  A: 

How about

container.find('button');
MvanGeest
+1 for beating me to the punch by 26 seconds :)
ivans
ouch! yea, that did the job, thanks! :-)
favo
Well, is this answer 'accepted'?
MvanGeest
yea, but I can only accept 15 minutes after asking the question :)
favo
"ouch" from my side. Sorry, I didn't know that; you can see I'm new here :)
MvanGeest
me too, so lets have fun ;-)
favo
+4  A: 

by using .find()

ivans
+1 for including a link to the documentation :D
MvanGeest