Reputation: 7030
Here is the structure of the content, I want to select all LI except the first two (ie no-link)
jQuery(document).ready(function(){
var nosubnav = jQuery('.first-level li:not(:has(ul))');
var nosubnavsize = jQuery('.first-level li:not(:has(ul))').size();
jQuery(nosubnav).css('border' , '1px solid red');
alert('List item which does not have submenu '+nosubnavsize);
});
div class="navigation-container">
<ul class="first-level">
<li><a href="#">No Link</a></li>
<li><a href="#">No Link</a></li>
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a>
<ul>
<li><a href="#">Link2.1</a></li>
<li><a href="#">Link2.2</a>
<ul>
<li><a href="#">Link 2.2.1</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#">Link </a></li>
</ul>
</div>
related Question : How to count li which does not have ul?
Upvotes: 3
Views: 2013
Reputation: 342635
$("ul.first-level > li:gt(1)").hide()
I'm assuming you're talking about the LIs which are on the top level, i.e. direct descendants of .first-level
. Otherwise, you can omit the parent child selector (>
).
http://api.jquery.com/gt-selector/
Upvotes: 9
Reputation: 8150
Just give the first two li´s a css-class (e.g. "noLink") and use
$("li:not('.noLink')").hide(); //or whatever
Upvotes: 0
Reputation: 943561
li + li + li, ul ul li
i.e. An item that is next to an item that is next to an item, or an item that is inside a list which is inside a list.
Upvotes: 0