2
<ul class="UIAPIPlugin-toc">
3
<li><a href="#overview">Overview</a></li>
4
<li><a href="#options">Options</a></li>
5
<li><a href="#events">Events</a></li>
6
<li><a href="#methods">Methods</a></li>
7
<li><a href="#theming">Theming</a></li>
9
<div class="UIAPIPlugin">
10
<h1>jQuery UI Accordion</h1>
12
<h2 class="top-header">Overview</h2>
13
<div id="overview-main">
14
<p>Make the selected elements Accordion widgets. Semantic requirements:</p>
15
<p>The markup of your accordion container needs pairs of headers and content panels, grouped by another element. By default, the header elements are anchors, assuming the following structure:</p>
16
<pre><div id="accordion">
18
<a href="#">First header</a>
19
<div>First content</div>
22
<a href="#">Second header</a>
23
<div>Second content</div>
26
<p>If you use a different element for the header, specify the header-option with an appropiate selector, eg. header: 'h3'. The content element must be always next to its header.</p>
27
<p>If you have links inside the accordion content and use a-elements as headers, add a class to them and use that as the header, eg. header: 'a.header'.</p>
28
<p>Use activate(Number) to change the active content programmatically.</p>
29
<div class="editsection" style="float:right;margin-left:5px;">[<a href="http://docs.jquery.com/action/edit/UI/API/1.7.1/Accordion?section=1" title="Edit section: NOTE: If you want multiple sections open at once, don't use an accordion">edit</a>]</div><a name="NOTE:_If_you_want_multiple_sections_open_at_once.2C_don.27t_use_an_accordion"></a><h4>NOTE: If you want multiple sections open at once, don't use an accordion</h4>
30
<p>An accordion doesn't allow more than one content panel to be open at the same time, and it takes a lot of effort to do that. If you are looking for a widget that allows more than one content panel to be open, don't use this. Usually it can be written with a few lines of jQuery instead, something like this:</p>
31
<pre>jQuery(document).ready(function(){
32
$('.accordion .head').click(function() {
33
$(this).next().toggle();
38
<pre>jQuery(document).ready(function(){
39
$('.accordion .head').click(function() {
40
$(this).next().toggle('slow');
45
<div id="overview-dependencies">
49
<li>UI Effects Core (Optional - only for non-default animations)</li>
52
<div id="overview-example">
54
<div id="overview-example" class="example">
55
<ul><li><a href="#demo"><span>Demo</span></a></li><li><a href="#source"><span>View Source</span></a></li></ul>
56
<p><div id="demo" class="tabs-container" rel="310">
57
A simple jQuery UI Accordion.<br />
59
<pre>$("#accordion").accordion();
61
<p></div><div id="source" class="tabs-container">
63
<pre><!DOCTYPE html>
66
<link type="text/css" href="http://jqueryui.com/latest/themes/base/ui.all.css" rel="stylesheet" />
67
<script type="text/javascript" src="http://jqueryui.com/latest/jquery-1.3.2.js"></script>
68
<script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.core.js"></script>
69
<script type="text/javascript" src="http://jqueryui.com/latest/ui/ui.accordion.js"></script>
70
<script type="text/javascript">
71
$(document).ready(function(){
72
$("#accordion").accordion();
76
<body style="font-size:62.5%;">
78
<div id="accordion">
79
<h3><a href="#">Section 1</a></h3>
82
Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
83
ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
84
amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
85
odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
88
<h3><a href="#">Section 2</a></h3>
91
Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet
92
purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor
93
velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In
94
suscipit faucibus urna.
97
<h3><a href="#">Section 3</a></h3>
100
Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis.
101
Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero
102
ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis
103
lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui.
106
<li>List item one</li>
107
<li>List item two</li>
108
<li>List item three</li>
111
<h3><a href="#">Section 4</a></h3>
114
Cras dictum. Pellentesque habitant morbi tristique senectus et netus
115
et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in
116
faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia
120
Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus.
121
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
135
<h2 class="top-header">Options</h2>
136
<ul class="options-list">
138
<li class="option" id="option-active">
139
<div class="option-header">
140
<h3 class="option-name"><a href="#option-active">active</a></h3>
142
<dt class="option-type-label">Type:</dt>
143
<dd class="option-type">Selector, Element, jQuery, Boolean, Number</dd>
145
<dt class="option-default-label">Default:</dt>
146
<dd class="option-default">first child</dd>
150
<div class="option-description">
151
<p>Selector for the active element. Set to false to display none at start. Needs «collapsible: true».</p>
153
<div class="option-examples">
154
<h4>Code examples</h4>
155
<dl class="option-examples-list">
158
Initialize a accordion with the <code>active</code> option specified.
161
<pre><code>$('.selector').accordion({ active: 2 });</code></pre>
166
Get or set the <code>active</code> option, after init.
170
var active = $('.selector').accordion('option', 'active');
172
$('.selector').accordion('option', 'active', 2);</code></pre>
180
<li class="option" id="option-animated">
181
<div class="option-header">
182
<h3 class="option-name"><a href="#option-animated">animated</a></h3>
184
<dt class="option-type-label">Type:</dt>
185
<dd class="option-type">Boolean, String</dd>
187
<dt class="option-default-label">Default:</dt>
188
<dd class="option-default">false</dd>
192
<div class="option-description">
193
<p>Choose your favorite animation, or disable them (set to false). In addition to the default, 'bounceslide' and 'easeslide' are supported (both require the easing plugin).</p>
195
<div class="option-examples">
196
<h4>Code examples</h4>
197
<dl class="option-examples-list">
200
Initialize a accordion with the <code>animated</code> option specified.
203
<pre><code>$('.selector').accordion({ animated: 'easeslide' });</code></pre>
208
Get or set the <code>animated</code> option, after init.
212
var animated = $('.selector').accordion('option', 'animated');
214
$('.selector').accordion('option', 'animated', 'easeslide');</code></pre>
222
<li class="option" id="option-autoHeight">
223
<div class="option-header">
224
<h3 class="option-name"><a href="#option-autoHeight">autoHeight</a></h3>
226
<dt class="option-type-label">Type:</dt>
227
<dd class="option-type">Boolean</dd>
229
<dt class="option-default-label">Default:</dt>
230
<dd class="option-default">true</dd>
234
<div class="option-description">
235
<p>If set, the highest content part is used as height reference for all other parts. Provides more consistent animations.</p>
237
<div class="option-examples">
238
<h4>Code examples</h4>
239
<dl class="option-examples-list">
242
Initialize a accordion with the <code>autoHeight</code> option specified.
245
<pre><code>$('.selector').accordion({ autoHeight: false });</code></pre>
250
Get or set the <code>autoHeight</code> option, after init.
254
var autoHeight = $('.selector').accordion('option', 'autoHeight');
256
$('.selector').accordion('option', 'autoHeight', false);</code></pre>
264
<li class="option" id="option-clearStyle">
265
<div class="option-header">
266
<h3 class="option-name"><a href="#option-clearStyle">clearStyle</a></h3>
268
<dt class="option-type-label">Type:</dt>
269
<dd class="option-type">Boolean</dd>
271
<dt class="option-default-label">Default:</dt>
272
<dd class="option-default">false</dd>
276
<div class="option-description">
277
<p>If set, clears height and overflow styles after finishing animations. This enables accordions to work with dynamic content. Won't work together with autoHeight.</p>
279
<div class="option-examples">
280
<h4>Code examples</h4>
281
<dl class="option-examples-list">
284
Initialize a accordion with the <code>clearStyle</code> option specified.
287
<pre><code>$('.selector').accordion({ clearStyle: true });</code></pre>
292
Get or set the <code>clearStyle</code> option, after init.
296
var clearStyle = $('.selector').accordion('option', 'clearStyle');
298
$('.selector').accordion('option', 'clearStyle', true);</code></pre>
306
<li class="option" id="option-collapsible">
307
<div class="option-header">
308
<h3 class="option-name"><a href="#option-collapsible">collapsible</a></h3>
310
<dt class="option-type-label">Type:</dt>
311
<dd class="option-type">Boolean</dd>
313
<dt class="option-default-label">Default:</dt>
314
<dd class="option-default">false</dd>
318
<div class="option-description">
319
<p>Whether all the sections can be closed at once. Allows collapsing the active section by the triggering event (click is the default).</p>
321
<div class="option-examples">
322
<h4>Code examples</h4>
323
<dl class="option-examples-list">
326
Initialize a accordion with the <code>collapsible</code> option specified.
329
<pre><code>$('.selector').accordion({ collapsible: true });</code></pre>
334
Get or set the <code>collapsible</code> option, after init.
338
var collapsible = $('.selector').accordion('option', 'collapsible');
340
$('.selector').accordion('option', 'collapsible', true);</code></pre>
348
<li class="option" id="option-event">
349
<div class="option-header">
350
<h3 class="option-name"><a href="#option-event">event</a></h3>
352
<dt class="option-type-label">Type:</dt>
353
<dd class="option-type">String</dd>
355
<dt class="option-default-label">Default:</dt>
356
<dd class="option-default">'click'</dd>
360
<div class="option-description">
361
<p>The event on which to trigger the accordion.</p>
363
<div class="option-examples">
364
<h4>Code examples</h4>
365
<dl class="option-examples-list">
368
Initialize a accordion with the <code>event</code> option specified.
371
<pre><code>$('.selector').accordion({ event: 'mouseover' });</code></pre>
376
Get or set the <code>event</code> option, after init.
380
var event = $('.selector').accordion('option', 'event');
382
$('.selector').accordion('option', 'event', 'mouseover');</code></pre>
390
<li class="option" id="option-fillSpace">
391
<div class="option-header">
392
<h3 class="option-name"><a href="#option-fillSpace">fillSpace</a></h3>
394
<dt class="option-type-label">Type:</dt>
395
<dd class="option-type">Boolean</dd>
397
<dt class="option-default-label">Default:</dt>
398
<dd class="option-default">false</dd>
402
<div class="option-description">
403
<p>If set, the accordion completely fills the height of the parent element. Overrides autoheight.</p>
405
<div class="option-examples">
406
<h4>Code examples</h4>
407
<dl class="option-examples-list">
410
Initialize a accordion with the <code>fillSpace</code> option specified.
413
<pre><code>$('.selector').accordion({ fillSpace: true });</code></pre>
418
Get or set the <code>fillSpace</code> option, after init.
422
var fillSpace = $('.selector').accordion('option', 'fillSpace');
424
$('.selector').accordion('option', 'fillSpace', true);</code></pre>
432
<li class="option" id="option-header">
433
<div class="option-header">
434
<h3 class="option-name"><a href="#option-header">header</a></h3>
436
<dt class="option-type-label">Type:</dt>
437
<dd class="option-type">Selector, jQuery</dd>
439
<dt class="option-default-label">Default:</dt>
440
<dd class="option-default">'> li > :first-child,> :not(li):even'</dd>
444
<div class="option-description">
445
<p>Selector for the header element.</p>
447
<div class="option-examples">
448
<h4>Code examples</h4>
449
<dl class="option-examples-list">
452
Initialize a accordion with the <code>header</code> option specified.
455
<pre><code>$('.selector').accordion({ header: 'h3' });</code></pre>
460
Get or set the <code>header</code> option, after init.
464
var header = $('.selector').accordion('option', 'header');
466
$('.selector').accordion('option', 'header', 'h3');</code></pre>
474
<li class="option" id="option-icons">
475
<div class="option-header">
476
<h3 class="option-name"><a href="#option-icons">icons</a></h3>
478
<dt class="option-type-label">Type:</dt>
479
<dd class="option-type">Object</dd>
481
<dt class="option-default-label">Default:</dt>
482
<dd class="option-default">{ 'header': 'ui-icon-triangle-1-e', 'headerSelected': 'ui-icon-triangle-1-s' }</dd>
486
<div class="option-description">
487
<p>Icons to use for headers. Icons may be specified for 'header' and 'headerSelected', and we recommend using the icons native to the jQuery UI CSS Framework manipulated by <a href="http://www.themeroller.com" class="external text" title="http://www.themeroller.com">jQuery UI ThemeRoller</a></p>
489
<div class="option-examples">
490
<h4>Code examples</h4>
491
<dl class="option-examples-list">
494
Initialize a accordion with the <code>icons</code> option specified.
497
<pre><code>$('.selector').accordion({ icons: { 'header': 'ui-icon-plus', 'headerSelected': 'ui-icon-minus' } });</code></pre>
502
Get or set the <code>icons</code> option, after init.
506
var icons = $('.selector').accordion('option', 'icons');
508
$('.selector').accordion('option', 'icons', { 'header': 'ui-icon-plus', 'headerSelected': 'ui-icon-minus' });</code></pre>
516
<li class="option" id="option-navigation">
517
<div class="option-header">
518
<h3 class="option-name"><a href="#option-navigation">navigation</a></h3>
520
<dt class="option-type-label">Type:</dt>
521
<dd class="option-type">Boolean</dd>
523
<dt class="option-default-label">Default:</dt>
524
<dd class="option-default">false</dd>
528
<div class="option-description">
529
<p>If set, looks for the anchor that matches location.href and activates it. Great for href-based state-saving. Use navigationFilter to implement your own matcher.</p>
531
<div class="option-examples">
532
<h4>Code examples</h4>
533
<dl class="option-examples-list">
536
Initialize a accordion with the <code>navigation</code> option specified.
539
<pre><code>$('.selector').accordion({ navigation: true });</code></pre>
544
Get or set the <code>navigation</code> option, after init.
548
var navigation = $('.selector').accordion('option', 'navigation');
550
$('.selector').accordion('option', 'navigation', true);</code></pre>
558
<li class="option" id="option-navigationFilter">
559
<div class="option-header">
560
<h3 class="option-name"><a href="#option-navigationFilter">navigationFilter</a></h3>
562
<dt class="option-type-label">Type:</dt>
563
<dd class="option-type">Function</dd>
565
<dt class="option-default-label">Default:</dt>
566
<dd class="option-default"> </dd>
570
<div class="option-description">
571
<p>Overwrite the default location.href-matching with your own matcher.</p>
573
<div class="option-examples">
574
<h4>Code examples</h4>
575
<dl class="option-examples-list">
578
Initialize a accordion with the <code>navigationFilter</code> option specified.
581
<pre><code>$('.selector').accordion({ navigationFilter: function(){ ... } });</code></pre>
586
Get or set the <code>navigationFilter</code> option, after init.
590
var navigationFilter = $('.selector').accordion('option', 'navigationFilter');
592
$('.selector').accordion('option', 'navigationFilter', function(){ ... });</code></pre>
602
<h2 class="top-header">Events</h2>
603
<ul class="events-list">
605
<li class="event" id="event-change">
606
<div class="event-header">
607
<h3 class="event-name"><a href="#event-change">change</a></h3>
609
<dt class="event-type-label">Type:</dt>
610
<dd class="event-type">accordionchange</dd>
613
<div class="event-description">
614
<p>This event is triggered every time the accordion changes. If the accordion is animated, the event will be triggered upon completion of the animation; otherwise, it is triggered immediately.
616
<pre>$('.ui-accordion').bind('accordionchange', function(event, ui) {
617
ui.newHeader // jQuery object, activated header
618
ui.oldHeader // jQuery object, previous header
619
ui.newContent // jQuery object, activated content
620
ui.oldContent // jQuery object, previous content
623
<div class="event-examples">
624
<h4>Code examples</h4>
625
<dl class="event-examples-list">
628
Supply a callback function to handle the <code>change</code> event as an init option.
631
<pre><code>$('.selector').accordion({
632
change: function(event, ui) { ... }
638
Bind to the <code>change</code> event by type: <code>accordionchange</code>.
641
<pre><code>$('.selector').bind('accordionchange', function(event, ui) {
653
<h2 class="top-header">Methods</h2>
654
<ul class="methods-list">
656
<li class="method" id="method-destroy">
657
<div class="method-header">
658
<h3 class="method-name"><a href="#method-destroy">destroy</a></h3>
660
<dt class="method-signature-label">Signature:</dt>
661
<dd class="method-signature">.accordion( 'destroy'
672
<div class="method-description">
673
<p>Remove the accordion functionality completely. This will return the element back to its pre-init state.</p>
678
<li class="method" id="method-disable">
679
<div class="method-header">
680
<h3 class="method-name"><a href="#method-disable">disable</a></h3>
682
<dt class="method-signature-label">Signature:</dt>
683
<dd class="method-signature">.accordion( 'disable'
694
<div class="method-description">
695
<p>Disable the accordion.</p>
700
<li class="method" id="method-enable">
701
<div class="method-header">
702
<h3 class="method-name"><a href="#method-enable">enable</a></h3>
704
<dt class="method-signature-label">Signature:</dt>
705
<dd class="method-signature">.accordion( 'enable'
716
<div class="method-description">
717
<p>Enable the accordion.</p>
722
<li class="method" id="method-option">
723
<div class="method-header">
724
<h3 class="method-name"><a href="#method-option">option</a></h3>
726
<dt class="method-signature-label">Signature:</dt>
727
<dd class="method-signature">.accordion( 'option'
731
, <span class="optional">[</span>value<span class="optional">] </span>
738
<div class="method-description">
739
<p>Get or set any accordion option. If no value is specified, will act as a getter.</p>
744
<li class="method" id="method-activate">
745
<div class="method-header">
746
<h3 class="method-name"><a href="#method-activate">activate</a></h3>
748
<dt class="method-signature-label">Signature:</dt>
749
<dd class="method-signature">.accordion( 'activate'
760
<div class="method-description">
761
<p>Activate a content part of the Accordion programmatically. The index can be a zero-indexed number to match the position of the header to close or a Selector matching an element. Pass -1 to close all (only possible with collapsible:true).</p>
768
<h2 class="top-header">Theming</h2>
769
<p>The jQuery UI Accordion plugin uses the jQuery UI CSS Framework to style its look and feel, including colors and background textures. We recommend using the ThemeRoller tool to create and download custom themes that are easy to build and maintain.
771
<p>If a deeper level of customization is needed, there are widget-specific classes referenced within the ui.accordion.css stylesheet that can be modified. These classes are highlighed in bold below.
774
<h3>Sample markup with jQuery UI CSS Framework classes</h3>
775
<div class="<strong>ui-accordion</strong> ui-widget ui-helper-reset"><br />
776
<h3 class="<strong>ui-accordion-header</strong> ui-helper-reset ui-state-active ui-corner-top"><br />
777
<span class="ui-icon ui-icon-triangle-1-s"/><br />
778
<a href="#">Section 1</a><br />
779
</h3><br />
780
<div class="<strong>ui-accordion-content</strong> ui-helper-reset ui-widget-content ui-corner-bottom <strong>ui-accordion-content-active</strong>"><br />
781
Section 1 content<br />
782
</div><br />
783
<h3 class="<strong>ui-accordion-header</strong> ui-helper-reset ui-state-default ui-corner-all"><br />
784
<span class="ui-icon ui-icon-triangle-1-e"/><br />
785
<a href="#">Section 2</a><br />
786
</h3><br />
787
<div class="<strong>ui-accordion-content</strong> ui-helper-reset ui-widget-content ui-corner-bottom"><br />
788
Section 2 content<br />
789
</div><br />
790
<h3 class="<strong>ui-accordion-header</strong> ui-helper-reset ui-state-default ui-corner-all"><br />
791
<span class="ui-icon ui-icon-triangle-1-e"/><br />
792
<a href="#">Section 3</a><br />
793
</h3><br />
794
<div class="<strong>ui-accordion-content</strong> ui-helper-reset ui-widget-content ui-corner-bottom"><br />
795
Section 3 content<br />
796
</div><br />
798
<p class="theme-note">
800
Note: This is a sample of markup generated by the accordion plugin, not markup you should use to create a accordion. The only markup needed for that is <br /><div><br />
801
   <h3><a href="#">Section 1</a></h3><br />
802
   <div><br />
803
      Section 1 content<br />
804
   </div><br />
805
   <h3><a href="#">Section 2</a></h3><br />
806
   <div><br />
807
      Section 2 content<br />
808
   </div><br />
809
   <h3><a href="#">Section 3</a></h3><br />
810
   <div><br />
811
      Section 3 content<br />
812
   </div><br />
821
Pre-expand include size: 29461 bytes
822
Post-expand include size: 52395 bytes
823
Template argument size: 31463 bytes
824
Maximum: 2097152 bytes
827
<!-- Saved in parser cache with key jqdocs_docs:pcache:idhash:3179-1!1!0!!en!2 and timestamp 20090319021840 -->