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.
Use the
:first
selectorTry,