here html code
<div id="parent"> <div id="computer"> <div id="items"> <div id="1">hp</div> <div id="2">compaq</div> <div id="3">toshiba</div> </div> </div> <div id="laptop"> <div id="1">i5</div> <div id="2">dual core</div> <div id="3">i3</div> </div> <div id="printer"> <div id="laser">hp laser</div> </div> <div id="cpu"> <div id="item"> <div id="1">pintuim</div> <div id="2">celeron</div> </div> </div> <div id="scanner"> <div id="canon"> <div>canon</div> </div> </div> </div>` i trying id of each first element of parent div array=[computer, laptop, printer, cpu, scanner]
here jquery code it's taking everything.
var = $("div.content :nth-child(1)")find("*").toarray();
please need thanks
there selector in jquery return first level of children: demo
var a=[]; $("#parent > div").each(function(){ // using > return first level of children a.push($(this).attr('id')); }); alert(a);
Comments
Post a Comment