138

I am working with jQuery UI Accordion and it works great, but I would like to have the accordion stay closed unless it I click on it.

I am using this code right now, which allows be to toggle it closed:

$("#accordion").accordion({ header: "h3", collapsible: true });

Is there a way to have it closed by default unless it is clicked?

Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
forrest
  • 10,570
  • 25
  • 70
  • 132

1 Answers1

295

Add the active: false option (documentation)..

$("#accordion").accordion({ header: "h3", collapsible: true, active: false });
Jarry
  • 1,891
  • 3
  • 15
  • 27
Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317
  • 51
    Note for other readers: You need "collapsible: true" to make "active: false" work. – Chuck Le Butt Apr 29 '14 at 13:36
  • 2
    Interesting. Is it possible to only serve it collapsed for mobile devices? On desktop computers I want the first tab open. On mobile devices I want all of them closed. – user5248 Jun 04 '15 at 22:51
  • 3
    @user5248 Just check browser in Javascript and make a conditionnal assignment – Reign.85 Sep 09 '15 at 12:15