Reputation: 643
I'm using the following jQuery for an accordion menu: http://jsfiddle.net/fPWeq/
rel = 0;
$('.sub-menu').hover(function(){ // findind mouse postion
rel = 1; // if mouse on submenu
}, function(){
rel = 0; // if mouse out submenu
});
$('.menu > li').live("click",function(){
if(!$(this).hasClass("active")){ // if not already opened
$('.sub-menu').slideUp(); // hide all other submenu
$('.sub-menu',this).slideDown(); // show which your clicked
$(".menu > li").remove('active'); // remove all active class in li
$(this).addClass('active'); //adding active class which your clicked li
}
else{
if(rel==0){
$('.sub-menu').slideUp(); // if clicked already opend parent that will close
$(this).removeClass('active'); // remove all active class
}
else{
}
}
});
;
I'm having difficulty figuring out how to stop active (pre-opened) submenus from closing and opening again when sub menu links within are clicked.
Any ideas what I am doing wrong?
Upvotes: 2
Views: 525
Reputation: 22710
Also .toggleClass("current-parent")
can be a good choice if you want to activate the opening/closing again.
Upvotes: 0
Reputation: 2597
remove class="current-parent"
and it shouldnt show the sub open.
Check here http://jsfiddle.net/fPWeq/1/
Upvotes: 1