I’m trying to beat a basic accordion style menu into submission – using jQuery.
Here’s the menu:
Here’s a snippet of code that gives it accordion functionality:
$('#access ul li').click(function(){
$('#access ul ul:visible').slideUp();
$(this).children('ul:hidden').slideDown();
});
The problem: a click on a sub-menu link makes the submenu slide up (and close).
I want to keep the submenu open when the submenu link is clicked, and slide up only when a top level links are clicked.
How can I select only the top level ul with jQuery to animate the submenu? Or is there a way to select the sub-menu link and “tell it” to keep the submenu open on click?
I would appreciate your wisdom!
It seems like you need to use the
>operator in CSS..foo > .barselects all elements with classbarthat is a direct child of an element with classfooGot it, working code:
To keep the menu from sliding back up again this works: