cebasso cebasso - 2 months ago 15
Javascript Question

JQuery - just walk in main li elements

If I have example

<ul class="treeview">
<li>
Something
</li>
<li>
Anything
<ul>
<li>
Anything 2
</li>
</ul>
</li>
<li>
Another thing
</li>
</ul>


So, I just want to walk into the main nodes... the code below

$('ul.treeview').children('li').each(


...

Shows even the Anything 2 in the walkthrough...

I just want to capture the main nodes in the UL... in this case

Something
Anything
Another thing

Noob question but, didn't figure out how to do that

Answer

Your code segment grabs all lis that are nested in the target. Im pretty sure $("ul.treeview > li") will do the trick.

Comments