Reputation: 15456
I have 3 layers of nested menus in <ul>
s, eg:
<div id="menu">
<ul>
<li><a href="somewhere.html">enu Item</a>
<ul>
<li><a href="somewhere.html">Menu Item 2</a>
<ul>
<li><a href="somewhere.html">Menu Item 3</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
I want to use Jquery to replace the href attribute of the first level of ul
s with #, but keep the href attributes on the 2nd and 3rd a tags.
Ive created this script which works for 2nd level ul
s but not the third level.
$("#menu ul li a").not("#ctamenu ul li ul a").attr("href", "#");
I have tried this:
$("#menu ul li a").not("#menu ul li ul a").not("#menu ul li ul li a").attr("href", "#")
But this doesnt work - the 3rd layer still has href='#'
Is there a way to do a "double not" statement?
Upvotes: 3
Views: 147
Reputation: 191769
The third level is nested in yet another ul
that you are missing, but it would be easier to use the child selector:
#menu > ul > li > a
Upvotes: 6
Reputation: 355
Depending on your situation, you might find it helpful to create add class="first-level"
on the first level anchor tags. Then you could use $('.first-level')
, which is more maintainable as the logic for your menu becomes more level dependent.
Upvotes: 0