tags:

views:

81

answers:

3

Can anyone point me towards a 'ready' jQuery Accordion with CSS that's light and is easy to implement. I do not want to use jQUery UI.

+2  A: 

I've deployed something like it here.

Here's the script (cleaned up as meo pointed out) for it:

$(document).ready( function() {
    $("div.accordian-text").hide();
    $("a.accordian-link").click( function() {
        $('div.accordian-text').slideUp()
        $(this).next("div.accordian-text").slideToggle();
        $(this).toggleClass("active");
    });
});

And the markup:

<a href="javascript:void(0);" class="accordian-link">Accordian Trigger</a>
<div class="accordian-text">
    <p>Hidden Text in Accordian element</p>
</div>
<!-- Repeat as needed -->
Zack
There's no CSS needed for this, just format the markup properly and use your site's styles.
Zack
you could simplify your function by using `slideToggle()` and `toggleClass()` so you could get rid of your `if else`, and you could replace `hasClass()` by `is()`
meo
Learn somethin' new every day, thanks for pointing that out :) Just added a story to pivotal to rewrite it
Zack
This is not working for some reason..When I click on the 2nd link, the 1st link does not slide up..please check.
ScG
+1 your are welcome: there is still optimization possible. you could put the `.toggleClass()` right after the first `$(this)` to avoid selecting the same dom element twice. And you could put just #something in the `href` and call `return false;` at the end of the click function. (or `preventDefault()`)
meo
@ScG, sorry, that was with the edit that meo suggested, I'd need to add some more code to collapse the old open dive/remove the old active tag. I've rolled it back to the working version.
Zack
@scg: you have to close all open slides first for that. you can to this by putting: `$('div.accordian-text').slideUp()` at the begging of the click function.
meo
meo: PUURRRRRFECT..do you blog somewhere?
ScG
zack: thanks for your response. you can reedit the code again and add what meo suggested
ScG
ScG: This has been done. Do I still get an answer accept? :P
Zack
check it out: http://jsfiddle.net/5xb4Q/2/
meo
@ScG: check my profile :P
meo
meo: Anyway to highlight this links..like in jQuery UI accordion, the headings are with a background color. How can i do it here?
ScG
Zack: Yes I will accept the answer in a short while :)
ScG
ZAck: Sorry meo's answer was spot-on. Thanks for your help too.
ScG
+2  A: 

I have also created an accordion here:

http://sarfraznawaz.wordpress.com/2010/03/09/creating-stylish-sliding-menu-with-jquery/

Sarfraz
I checked it..not what I need..thanks.
ScG
@ScG: The explanation is there on how to do it, also you can download the demo and anaylyze/modify that. Thanks
Sarfraz
A: 

http://jsfiddle.net/5xb4Q/12/

i have corrected some bugs in the version i have posted in the comments, this should work for you.

meo
Awesome..this looks great
ScG