Select all li's but not children

Posted by fire on Stack Overflow See other posts from Stack Overflow or by fire
Published on 2010-03-12T12:37:00Z Indexed on 2010/03/12 12:47 UTC
Read the original article Hit count: 372

Filed under:
|

I have this code:

$li = $("li", this)

Which is selecting all of the li's in my code. This works fine however I want $li to exclude the li's that are within a submenu.

    <ul id="navigation">
        <li><a href="#">blah 1</a></li>
        <ul id="subnav">
            <li><a href="#">sub 1</a></li>
            <li><a href="#">sub 2</a></li>
            <li><a href="#">sub 3</a></li>
        </ul>
        </li>
        <li><a href="#">blah 2</a></li>
        <li><a href="#">blah 3</a></li>
        <li><a href="#">blah 4</a></li>
        <li><a href="#">blah 5</a></li>
    </ul>

So $li would only reference the blah's not the sub's.

I thought it was something like:

$li = $("li", this).parents()

But this doesn't do what I want.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery