jeffchannell.com

Tiny jQuery Accordion Menu

Posted in JavaScript
2009-03-28 22:23:50 +0000 UTC

I wrote a little jQuery script for accordion menus. Hope you like it:

First, create your HTML markup as follows:

title 1

content 1

title 2

content 2

Then add this to your javascript:

/* jeff's tiny accordian */
var aMenu = function( sel ) {
	$(sel+' div').hide();
	$(sel+' h4').click(aMenuClick);
}
var aMenuClick = function() {
	$(this).next('div').slideToggle(500).siblings('div').slideUp(500);
	return $(this).next('div').length > 0 ? false : true;
}
$(window).bind( 'load', function() { aMenu( 'div#sel' ); } );