Apr
Lightweight JavaScript Accordion with CSS
Posted by Michael in CSS, JavaScriptThe JavaScript accordion above is only 1.5kb. If you have a small project that could use an accordion and don’t want to include an entire JavaScript framework to do the job then give this script a try.
You will need to call the following function in your body onload where the first parameter is the div id of the accordion parent and the second tells the script which section to expand onload.
slider.init('slider',1)
There is no other JavaScript that needs to be added to the HTML. The onload function parses the children of the parent accordion div and adds the appropriate mouse events to the headings. This has been tested in Firefox 2/3, IE 6/7/8, Opera and Safari.
Click here to download the source code.
Updated 5/27/2008 - Slightly minified the code cutting off 1kb and added the script into a global namespace.
Updated 6/19/2008 - Shaved of a few bytes and added change the “c” variable to identify which section to be expanded onload.
in the source code imported js file is not the same name that in the folder remove the additional js in the html or in the js packed file
priyantha on 19 Apr 2008 at 7:15 am