SHVDave
SHVDave

Reputation: 1

jquery accordion: open specified panel on close other panel

I am totally new to JQuery and javascript and could really use some help.

I want put together an accordion that has 8 panels and the default panel is #8. It is open when the page loads. By default, the #8 will close when I open any other panel, and stays closed unless I specifically open it, regardless of which other panel I open or close.

What I need to know is this: Is it possible to automatically open #8 each time I close an open panel.

For example, I open panel 3, which closes all currently open panels. When I close panel 3, I want panel 8 to open automatically.

Is that possible?

Thank you

Upvotes: 0

Views: 1596

Answers (1)

omma2289
omma2289

Reputation: 54619

Yes it is possible. Here's an example using jQuery UI:

$(function() {
    var activePanel = 2; //Set to the zero-based index of the panel you want to open
    $( "#accordion" ).accordion({
        collapsible: true,
        active: activePanel,
        activate: function(event,ui){
            //If a panel other than our default is collapsed
            if(!ui.newPanel.length && $(this).find('.ui-accordion-content').index(ui.oldPanel) != activePanel){
                $(this).accordion('option','active',activePanel);
            }
        }
    });
  });

Demo fiddle

Upvotes: 1

Related Questions