Selecting with jQuery
Selecting with jQuery
I have a HTML menu (notice the submenu):
-
<ul class="buttons">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">News</a>
<ul>
<li><a href="#">Submenu</a></li>
</ul>
</li>
<li><a href="#">Services</a></li>
<li><a href="#">Contact</a></li>
</ul>
I get the index of each element, using the jQuery index. For example, I get "0" for Home, "1" for About, "2" for News, "3" for Submenu, "4" for Services and "5" for Contact.
-
var links = $(".buttons li a");
var indexNumber = links.index(this);
But I don't want to get the index of sub menu elements. I need something like: index number "0" for Home, "1" for About", "2" for News, "3" for Services and "4" for Contact. In other wordds: I don't want to get the index of 'submenu'.
Any idea how to do this with jQuery? Thanks!