jquery - Target first element inside its parent -


i'm having trouble targeting first element inside list item using :first.

<li data-id="321">     <ul>         <li data-id="380">             <ul>                 <li data-id="385"></li>             </ul>         </li>         <li data-id="382"></li>     </ul> </li> 
$(".drop .position").click(function() {     $this = $(this);     $targetid = $(".box-cont.active ").closest("li.box").data("id");     $childrenarray = new array();     if ($target.find("ul:first").find("li").length > 0) {         $target.find("ul:first").find("li").each(function() {             $this = $(this);             $childrenarray.push($this.data("id"));         });         alert($childrenarray);     } else {         alert("no children");     } 

i'm trying target children of first ul inside 321. instead, i'm adding 380, 382, , 385 array when want add 380 , 382.

it's gonna find li, indeed. want direct descendants. either replace find children or use "ul:first>li" jquery selector


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -