Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing items at deeper levels using children() in jQuery

Tags:

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 though 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?

like image 679
favo Avatar asked May 29 '10 12:05

favo


2 Answers

How about

container.find('button');
like image 51
MvanGeest Avatar answered Oct 19 '22 14:10

MvanGeest


by using .find()

like image 32
ivans Avatar answered Oct 19 '22 15:10

ivans