Reputation: 6511
I have a simple menu system on my website. Demo: http://jsfiddle.net/a41xkr9z/2/
My Problem: when I click 'Projects' it displays the submenu. However, if you click 'Projects' again, it hides the menu. How do I prevent this?
Javascript:
$('#menu-primary-menu>li>a').click(function() {
$(this).parents("ul").find("li>ul").not($(this).next()).hide();
$(this).next().toggle();
});
Upvotes: 0
Views: 48
Reputation: 23
If you use .toggle()
the function change the status of the element hidden/shown.
Use .show()
or .hide()
if you only want one action.
Upvotes: 0
Reputation: 1126
$('#menu-primary-menu>li>a').click(function() {
$(this).parents("ul").find("li>ul").not($(this).next()).hide();
$(this).next().fadeIn();
});
Upvotes: 1