Is there a more efficient way to hide elements?


#1


Madison Square Market - JQuery Project


It works


var main = function () {
  
  $('.cart').click(function(){
    $(".account .dropdown-menu").hide();
    $(".help .dropdown-menu").hide();
    $(".cart .dropdown-menu").toggle();
  });
  
  $('.account').click(function(){
    $('.cart .dropdown-menu').hide();
    $('.help .dropdown-menu').hide();
    $(".account .dropdown-menu").toggle();
  });
  
  $('.help').click(function(){
    $('.cart .dropdown-menu').hide();
    $(".account .dropdown-menu").hide();
    $(".help .dropdown-menu").toggle();
  });
  
};

$(document).ready(main);


#2

Here's what I came up with..edited in the hiding part which I missed initially.

$(document).ready(function(){
  
  $('.dropdown').click(function(){
    //hide all menus first.
    $('.dropdown-menu').hide();
    // now toggle just this one!
         $(this).children('.dropdown-menu').toggle();
  
});
  
});

#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.