john
john

Reputation: 3

JQuery Accordion Default State

I need some help with this accordion. Please see the demo here. http://jsfiddle.net/a36RL/

$(document).ready(function() {
    $('div.accordionButton').click(function() {
        $('div.accordionContent').slideUp('slow');    
        $(this).next().slideDown('slow');
    });
    $("div.accordionContent").hide();
});

I need to make a little changes in it.

  1. I want the first tab down by default.
  2. If a tab is already down, and that tab is clicked again, there should not be anything (Currently it slides up and then down again).

Thanks for the help.

Upvotes: 0

Views: 79

Answers (1)

Chandu
Chandu

Reputation: 82933

You can trigger the click event on the first button to open the first tab. Try this:

$(document).ready(function() {
    $('div.accordionButton').click(function() {
    if($(this).next().is(":visible")){
        return;
    }

        $('div.accordionContent').slideUp('slow');    
        $(this).next().slideDown('slow');
    });
    $("div.accordionContent").hide();
    $("div.accordionButton:eq(0)").click();
});

Working example @:

http://jsfiddle.net/a36RL/7/

Upvotes: 1

Related Questions