elgati
elgati

Reputation: 103

Jquery filter out nested lists

I am trying to select all the li elements in a list using Jquery, but not the li's in nested ul's inside some of those. In other words, only first-level list items.

<ul>
  <li>This one</li>
  <li>This one</li>
  <li>This one
   <ul>
     <li>Not this one</li>
     <li>Not this one</li>
   </ul>
  </li>
  <li>This one</li>
</ul>

I have tried :not() and > and :first-child, but I always get either one element or dozens of them.

It's for a Wordpress generated menu so I don't want to change the id and class names which would probably be the easiest way.

Upvotes: 2

Views: 111

Answers (1)

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

Use the :first selector

Try,

$('ul:first > li')

Upvotes: 1

Related Questions