Saturday, 28 March 2009 17:23

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

First, create your HTML markup as follows:

<div id="sel">
  <h4>title 1</h4><div>content 1</div>
  <h4>title 2</h4><div>content 2</div>
</div>

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' ); } );
Last Updated on Sunday, 26 April 2009 21:14
 
Comments (1)
1 Thursday, 17 December 2009 21:58
dude
Why waste so much code? Just do it like this:

$(window).bind('load', function() {
$('div#sel div').hide();
$('div#sel h4').click(function() {
$(this).next('div').slideToggle(500).siblings('div').slideUp(500);
});
});

If you had another intention for all the extraneous code you should have said so

Add your comment

Your name:
Comment:
  The word for verification. Lowercase letters only with no spaces.
Word verification:

The Joomla!® name is used under a limited license from Open Source Matters in the United States and other countries. Jeff Channell is not affiliated with or endorsed by Open Source Matters or the Joomla!® Project.

Santorum
Joomla Extensions