Search code examples
javascriptjqueryjquery-mobilepositionjquery-mobile-collapsible

jqm change position of collapsible


I just want to change the position of collapsible col2 before collapsiblecol1. Finally the order should be: 1.col2 2.col1 3.col3

<div data-role="content">
    <div id="List" data-role="collapsible-set">
        <div data-role="collapsible" data-content-theme="c" id="col1">
            <h3>Header 1</h3>
            <p>Text 1</p>
        </div>
        <div data-role="collapsible" data-content-theme="c" id="col2">
            <h3>Header 2</h3>    
            <p>Text 2</p>
        </div>
        <div data-role="collapsible" data-content-theme="c" id="col3">
            <h3>Header 3</h3>    
            <p>Text 3</p>
        </div>
    </div>
</div>

Solution

  • You should move the collapsible and then call refresh:

    $('#col1').after($('#col2')); // Move the node
    $('#List').collapsibleset('refresh'); // Refresh the collapsible set
    

    Edited: the 'refresh' method should be called in the collapsibleset plugin (not on the collapsible plugin). -Thanks Omar for the correction.