So I have more dropdown menus on a page, and when I click one, how can I hide the other ones which are open?Here is my code:
$('nav ul li.sub-menu > a,nav ul li.sub-menu2 > a').click(function(){
$('.open-menu').toggle();
$('.active_menu').removeClass('active_menu');
$(this).parent().toggleClass('active_menu');
$(this).parent().find('ul').toggleClass('open-menu').toggle();
return false;
});
I tried with the .open-menu to add to a dropdown when it's active, and active_menu it's just to style the active link.
//Le
$(document).ready(function() {
$('.sub-menu > a').click(function(){
$('.sub-menu ul').toggleClass('open-menu');
$(this).parent().find('ul').toggleClass('open-menu');
return false;
});
});
Now it doesn't open the menu that I click on, it opens other menu
<li>which are not definitely in<ul>