javascript - Getting nth level children using jquery -
i have following situation. want access "nth" children using jquery.
<div id="root"> <div id="block"> <div>level 1 <div>level 2</div> <div>level 3 <div>level 3.1</div> <div>level 3.2</div> </div> <div>level 4 <div>level 4.1 <div>level 4.1.1</div> </div> <div>level 4.2</div> </div> </div> <div>level 1 <div>level 2 <div>level 3 <div>level 3.1</div> </div> <div>level 4</div> </div> <div>level 5</div> </div> <div>level 1 <div>level 2</div> <div>level 3 <div>level 3.1</div> <div>level 3.2</div> </div> <div>level 4 <div>level 4.1</div> <div>level 4.2</div> </div> <div>level 5</div> </div> </div> </div>
i have _div = $("").appendto( "#root" ); want access _nth level children through it. _nth may be-> 2/3/4 example: want access 3rd level children of _div i.e. level 3.1,level 3.2 etc. how can access it? please help.
$( "#root div:nth-child(2)" )
will give you
<div>level 3 <div>level 3.1</div> <div>level 3.2</div> </div>
Comments
Post a Comment