michaelmcgurk
michaelmcgurk

Reputation: 6511

Show/Hide SubMenu issue

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

Answers (3)

ChristianGH
ChristianGH

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

Alok Deshwal
Alok Deshwal

Reputation: 1126

$('#menu-primary-menu>li>a').click(function() {
  $(this).parents("ul").find("li>ul").not($(this).next()).hide();
 $(this).next().fadeIn();
});

Upvotes: 1

OstrichProjects
OstrichProjects

Reputation: 318

Change $(this).next().toggle(); to $(this).next().show();.

Upvotes: 2

Related Questions