139

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?

1 Answer 1

296

Add the active: false option (documentation)..

$("#accordion").accordion({ header: "h3", collapsible: true, active: false });
3
  • 51
    Note for other readers: You need "collapsible: true" to make "active: false" work. Apr 29, 2014 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 4, 2015 at 22:51
  • 3
    @user5248 Just check browser in Javascript and make a conditionnal assignment
    – Reign.85
    Sep 9, 2015 at 12:15

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.