This is a simple Accordion menu done in JQuery. Links with subitems under them will expand the submenu when clicked. Items that don't have subitems are normal links. (example link to Marco's blog). The menu initialises with the first submenu expanded.
If this code snippet is useful for you feel free to download it and use it on your (non commercial) website.
This snipped is discussed on my blog in this post.
By default, the menu will launch in collapsed state and function like an accordion.
Same as the first example but with the first submenu expanded when the page loads. This is achieved by adding a CSS class expandfirst to the unordered list.
This is a standard expandable menu without accordion functionality. This is achieved by adding a CSS class named noaccordion to the unordered list.
This menu works like an accordion when one menu item is already expanded but will collapse completely when the expanded item is clicked. Additionally it has the first item expanded at page load. This is achieved by adding a CSS class named collapsible and another CSS class named expandfirst like in example 2.
function initMenu() {$('#menu ul').hide();$('#menu ul:first').show();$('#menu li a').click(function() {var checkElement = $(this).next();if((checkElement.is('ul')) && (checkElement.is(':visible'))) {return false;}if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {$('#menu ul:visible').slideUp('normal');checkElement.slideDown('normal');return false;}});}$(document).ready(function() {initMenu();});Just want it as a simple collapsing / uncollapsing menu? Find it here. Even less code.