views:

21

answers:

2

I have 3 menus that use this .toggle and when I switch between menus it requires a second click for the menu to click on again. How do I make the second function stop if another menu is shown?

  $(".dd").toggle(function() {
      $("ul a", this).click(function(e) {
         e.stopPropagation();
      });
      $(".contextMenu").hide();
      $("ul", this).show();     
    }, 
    function() {
      $("ul", this).hide();
    }
  );
A: 

I got this to work how I wanted it. Thanks to this thread http://stackoverflow.com/questions/244392/jquery-toggle-state

  $(".dd").click(function() {
    $("ul", ".dd").not(this).hide();
    $("ul", this).toggle();
  });
  $(".wrapper").click(function() {
    $("ul", ".dd").hide();
  });
sway
A: 

I think instead of a .toggle() you want just a .click() here, like this:

$(".dd ul a", this).click(function(e) {
  e.stopPropagation();
});
$(".dd").click(function() {  
  $(".contextMenu").hide();
  $(this).find("ul").toggle();
  //possibly to hide others: $(".dd").not(this).find("ul").hide();
});
Nick Craver