JQuery child selector expression
<div id="div">
<div> <!-- first level -->
<div> <!-- second level -->
<div>1.1</div> <!-- third level -->
<div>1.2</div>
</div>
<div>
<div></div>
<div>2.2</div>
</div>
</div>
</div>
What are the expressions of the jQuery selector to select the following elements:
1. div, commented on by the first level
2. Divas, commented on by the second level
3. Divas, commented on by the third level
+3
5 answers
The key to all of them is either a selector >(child) or a method children().
First level:
$("#div > div")...
$("#div").children("div")...
Second level:
$("#div > div > div")...
$("#div").children("div").children("div")...
Third level:
$("#div > div > div > div")...
$("#div").children("div").children("div").children("div")...
(, div), children(). , :
$("#div").children().children()...
+5