Ad

Sub Nav Not Directing To Page (jquery)

I have basic markup for a drop down nav, nested lists.

The user will click on the top nav item, which will open up the sub nav, but my sub nav links aren't working.

It is in a CMS so I must have the links for the placeholder pages there.

Markup:

<ul class="navtop">
<li><a target="_blank" rel="nofollow noreferrer" href="">Who</a>
  <ul>
     <li><a target="_blank" rel="nofollow noreferrer" href="">Sub Item 1</a></li>
     <li><a target="_blank" rel="nofollow noreferrer" href="">Sub Item 2</a></li>
     <li><a target="_blank" rel="nofollow noreferrer" href="">Long Sub Item 3</a></li>
     <li><a target="_blank" rel="nofollow noreferrer" href="">Sub Item 4</a></li>
  </ul>
</li>
<li><a target="_blank" rel="nofollow noreferrer" href="">What</a>
  <ul>
     <li><a target="_blank" rel="nofollow noreferrer" href="">Sub Item 1</a></li>
     <li><a target="_blank" rel="nofollow noreferrer" href="">Sub Item 2</a></li>
     <li><a target="_blank" rel="nofollow noreferrer" href="">Long Sub Item 3</a></li>
     <li><a target="_blank" rel="nofollow noreferrer" href="">Sub Item 4</a></li>
  </ul>
</li>
</ul>

Javascript:

$(".navtop li").click(function(){
    $(this).toggleClass("show");        
    $(this).siblings(".show").toggleClass("show");
    return false;
});

css:

#headernav .navtop li.show ul
{
display: block;
}

I tried adding a 'return true' for $(".navtop li ul li a") but it didn't work. Suggestions?

Ad

Answer

Turns out this worked:

$(".navtop > li > a").click(function(){
    $(this).parent('li').toggleClass("show");       
    $(this).parent('li').siblings(".show").toggleClass("show");
    return false;
});
Ad
source: stackoverflow.com
Ad