Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

J Query Toggle sub menus not working as desired

I have a function that toggles a sub-menu when the parent is clicked.  This works fine.  However, if I click on another menu choice (parent) the sub-menu toggles open but the prior sub-menu that was toggled open stays open.  What I want is for each toggled sub-men closes if another parent is clicked so only one sub-menu is open at a time.

$("#menu-mobile .sub-menu").hide();
   
$('#menu-mobile').children().click(function(){
    $(this).children('.sub-menu').slideToggle('slow'); 
});

Open in new window

Avatar of Zvonko
Zvonko
Flag of North Macedonia image

You mean this:


$("#menu-mobile .sub-menu").hide(); 
    
$('#menu-mobile').children().click(function(){ 
   $("#menu-mobile .sub-menu").hide(); 
   $(this).children('.sub-menu').slideToggle('slow');  
});

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial