How can I select the link elements of only the parent <ul>
from a list like this?
<ul>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a>
<ul>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
</ul>
</li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
So in css ul li a
, but not ul li ul li a
Thanks
$("ul > li a")
But you would need to set a class on the root ul if you specifically want to target the outermost ul:
<ul class="rootlist">
...
Then it's:
$("ul.rootlist > li a")....
Another way of making sure you only have the root li elements:
$("ul > li a").not("ul li ul a")
It looks kludgy, but it should do the trick