Accessing items at deeper levels using children() in jQuery

Posted by favo on Stack Overflow See other posts from Stack Overflow or by favo
Published on 2010-05-29T12:58:03Z Indexed on 2010/05/29 13:02 UTC
Read the original article Hit count: 179

Filed under:
|
|

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!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery