Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I expand/collapse content of JQuery ui Accordion by click another elements too?

By default, there are headers of contents to control expand/collapse.But in my situation,I could expand/collapse the contents by another elements ,too. For example:

the basic structure of jquery ui accodion code:

<script>
    $(function() {
        $( "#accordion" ).accordion();
    });
    </script>



<div class="demo">

<div id="accordion">
    <h3><a href="#">Section 1</a></h3>
    <div>
        <p>
        Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
        ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
        amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
        odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
        </p>
    </div>
......
</div>

and now. I have another elements,just like :

<ul id="another elements can expand/collapse too">
    <li><a href="">  expand/collapse contents of section1 of id=accordion too</a></li>
........
</ul>

thank you very much!!

like image 991
qinHaiXiang Avatar asked Jan 13 '11 14:01

qinHaiXiang


People also ask

How do you expand all accordions?

If you want to expand a specified item of Accordion, you need to set the isExpand parameter to true and specify the index of the corresponding accordion pane in index parameter. The index of the HTML 5 Accordion items is starting from 0.

Which method can perform an action on accordion elements such as selecting deselecting the accordion menu?

Second Method. The accordion ("action", params) method is used to perform an action on accordion elements, such as selecting/de-selecting the accordion menu. The action is specified as a string in the first argument (e.g., "disable" disables all menus).

How to use accordion in jQuery?

jQuery - Widget accordion The Widget accordion function can be used with widgets in JqueryUI. Accordion is same like as Tabs,When user click headers to expand content that is broken into logical sections.

What is UI accordion?

In web design, an accordion is a type of menu that displays a list of headers stacked on top of one another. When clicked on (or triggered by a keyboard interaction or screen reader), these headers will either reveal or hide associated content.


2 Answers

Collapse accordion tab:

$('.accordion').accordion('activate', false );

Expand first accordion tab:

$('.accordion').each(function (idx, item) {
    if ($(item).accordion("option", "active") === false) {
        $(item).accordion('activate', 0);
    }
});
like image 67
Maksym Kozlenko Avatar answered Sep 22 '22 19:09

Maksym Kozlenko


After update of JQuery UI there is no "active" method on accordion. So, to collapse all accordions use:

$('.accordion').accordion('option', {active: false});
like image 35
DrafFter Avatar answered Sep 20 '22 19:09

DrafFter