Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Accordion open collapsed

using jquery v1.3.2 and jQuery UI 1.7.1

I have 1 tab control with 3 tabs in it. Each tab contains 1 accordion control.

$(document).ready(function() {
$('#acc1').accordion({ collapsible: true, autoHeight: false });     

$('#acc1').accordion({ collapsible: true, autoHeight: false });     

$('#acc1').accordion({ collapsible: true, autoHeight: false });

$('#tabControl').tabs();

});

tabControl is not visible at page load. There is button that opens it.

$("#btnShow").bind("click", function() {
$('#tabControl').slideToggle("slow");
});

I can't find the way to have all accordion controls collapsed. Every time I show tabControl, accordions in it have first item always expanded.

I have tried this:

$('#acc1First').css('display', 'none');
$('#acc2First').css('display', 'none');
$('#acc3First').css('display', 'none');

$('#acc1First').slideUp();
$('#acc2First').slideUp();
$('#acc3First').slideUp();

but it bugges sometimes, first item have to be clicked 2 times to work properly etc.

Is there any way to initialize accordion control with all items collapsed ?

Thanks

like image 592
Andrija Avatar asked May 03 '09 20:05

Andrija


People also ask

How do you collapse an accordion by default?

To create an accordion that is collapsed by default, we need to set the 'active' property of the jQuery Accordion as false. Syntax: $("#demoAccordion"). accordion({ collapsible: true, active: false});

How do you close an accordion when another opens?

By default all accordions are closed. User can open any of them and those will stay opened until the user manually closes them by clicking on the accordion title.


2 Answers

Try this

$('#acc1').accordion({ 
    collapsible: true, 
    autoHeight: false, 
    active: false 
});
like image 94
Ólafur Waage Avatar answered Oct 21 '22 02:10

Ólafur Waage


I have created this one:

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

like image 21
Sarfraz Avatar answered Oct 21 '22 01:10

Sarfraz