$('header ul.navbar-nav li.dropdown a').on('click', function(){ if($(this).next().css("display")=="block"){ $(this).next().css("display", "none"); } else{ $(this).parent().parent().find("ul").css("display", "none"); $(this).next().css("display", "block"); } return false; });