Reputation: 163
<div id="tab">
<div class="" style="margin: 10px;">
<div id="someVerylongId1" style="height: 400px; position: relative;">
</div>
</div>
<div class="" style="margin: 10px;">
<div id="someVerylongId2" style="height: 400px; position: relative;">
</div>
</div>
<div class="" style="margin: 10px;">
<div id="someVerylongId3" style="height: 400px; position: relative;">
</div>
</div>
<div>
I want to select all divs not specifying ids or checking any another attributes, is it possible to do like that?
Here is my try:
$("#tab div div")
but looks like is selecting not exactly correct. Need help.
The problem is, my selector returns more elements that it should
Upvotes: 15
Views: 92062
Reputation: 103
You could also use find method of JQuery. Find will return all the descendant elements of the selected element.
$(selector).find(filter criteria)
ex:
$("div#tab").find("div")
Upvotes: 2
Reputation: 2187
$("div > div", "#tab");
That will select all children of divs using the context of #tab
http://jsfiddle.net/HenryGarle/mHpMM/
Upvotes: 15
Reputation: 189
Try this
$("#tab > div > div")
You can use child selector (>) for select the child. See more info: http://api.jquery.com/child-selector/
Upvotes: 12