Reputation: 139982
<div id="container">
<div>
<div>
</div>
</div>
<div>
<div>
</div>
</div>
<div>
<div>
</div>
</div>
</div>
$('#container').find('div')
will also include those inner divs.
How to fetch only the 3 top-level divs?
Upvotes: 1
Views: 1693
Reputation: 22023
You can use jQuery's children([expr]) function to do this.
Something like
$("#container").children("div")
Upvotes: 2
Reputation: 827704
Select only the direct descendants with the parent > child selector:
$('#container > div')
Or the Traversing/children function:
$('#container').children('div')
Upvotes: 1