Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select only top-level li in recursive menu?

Tags:

html

jquery

dom

css

How do I select only first-level li's? If I do 'ul li', it also selects the children. Is there a way to select only the top level and not the children using CSS? If not, I am ok with using jQuery, but how would I select it in that case too?

<ul>
    <li class="administration first">
        <a href="/administration.aspx"><span>Administration</span></a>
        <ul>
            <li class="users first selected"><a href="/administration/users.aspx"><span>Users</span></a></li>
            <li class="forms last"><a href="/administration/forms.aspx"><span>Forms</span></a></li>
        </ul>
        <div style="clear: both;"></div>
    </li>
    <li class="analytics"><a href="/analytics.aspx"><span>Analytics</span></a></li>
    <li class="options"><a href="/options.aspx"><span>Options</span></a></li>
    <li class="system last"><a href="/system.aspx"><span>System</span></a></li>
</ul>
like image 435
TruMan1 Avatar asked Oct 08 '10 15:10

TruMan1


2 Answers

You would need the element or class which is above the first ul, then specify {parent-selector} > ul > li.

like image 53
ClarkeyBoy Avatar answered Sep 20 '22 17:09

ClarkeyBoy


$("ul:first > li").

like image 25
MrAwesome Avatar answered Sep 18 '22 17:09

MrAwesome