jQuery UI & Accordion: Sortable

jQuery UI Accordion – Sortable

You can drag the header to re-order panels.

<!doctype html>
<html lang='en'>
<head>
    <meta charset='utf-8'>
    <title>jQuery UI Accordion - Sortable</title>
    <link rel='stylesheet' href='//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css'>
    <script src='//code.jquery.com/jquery-1.9.1.js'></script>
    <script src='//code.jquery.com/ui/1.10.4/jquery-ui.js'></script>
    <link rel='stylesheet' href='https://codecrawl.com/code/jqueryui/jqueryui_style.css'>
    <style>
        /* IE has layout issues when sorting (see #5413) */
        .group {
            zoom: 1
        }
    </style>
    <script>
        $(function () {
            $('#accordion')
                    .accordion({
                        header: '> div > h3'
                    })
                    .sortable({
                        axis: 'y',
                        handle: 'h3',
                        stop: function (event, ui) {
                            // IE doesn't register the blur when sorting
                            // so trigger focusout handlers to remove .ui-state-focus
                            ui.item.children('h3').triggerHandler('focusout');
                        }
                    });
        });
    </script>
</head>
<body>

<div id='accordion'>
    <div class='group'>
        <h3>Section 1</h3>

        <div>
            <p>Content of section 1.</p>
        </div>
    </div>
    <div class='group'>
        <h3>Section 2</h3>

        <div>
            <p>Content of section 2.</p>
        </div>
    </div>
    <div class='group'>
        <h3>Section 3</h3>

        <div>
            <p>Content of section 3.</p>
            <ul>
                <li>List item one</li>
                <li>List item two</li>
                <li>List item three</li>
            </ul>
        </div>
    </div>
    <div class='group'>
        <h3>Section 4</h3>

        <div>
            <p>Content of section 4</p>
        </div>
    </div>
</div>

</body>
</html>
Try The Code

Series Navigation<< jQuery UI & Accordion: Displaying Collapsible Content Panels
jQuery UI & Accordion: Allow All Sections To Be Collapsible >>