Gogol
Gogol

Reputation: 163

How to select div inside div inside div with jquery

<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

Answers (4)

Amir
Amir

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

Henry
Henry

Reputation: 2187

$("div > div", "#tab");

That will select all children of divs using the context of #tab

http://jsfiddle.net/HenryGarle/mHpMM/

Upvotes: 15

Jordi
Jordi

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

kritya
kritya

Reputation: 3372

$("#tab").siblings();

[docs]

Quote from jquery:

Get the siblings of each element in the set of matched elements, optionally filtered by a selector.

Upvotes: -3

Related Questions