2

I just installed an accordion / collapsible element and on the page, it is functioning correctly. However, when navigating away and back, the previous 'close' action of the collapse is not retained. It's still open when I return.

Is there a way to retain the previous action of the collapse?

<div class="row">
    <button type="button" class="btn btn-info btn-xs" data-toggle="collapse" data-target="#demo">MORE</button>
    <div id="demo" class="collapse in">
        <div class="row">
            Foo bar - Foo bar
        </div>
    </div>
</div>
Alex Pan
  • 4,341
  • 8
  • 34
  • 45
PatrickLightning
  • 117
  • 1
  • 12

1 Answers1

2

you can simply check the documentation right here: Bootstrap collapse how to collapse or not collapse your accordion.

$('#demo').collapse({
  toggle: false //you can simple untoggle your collapse on page load. 
})

There is many more you can do too like:

.collapse('toggle') //Toggles a collapsible element to shown or hidden.

.collapse('show') //Shows a collapsible element.

.collapse('hide') //Hides a collapsible element.

Update

to save the current state of the dropdown, I will suggest you use Jquery.cookies to do so. This is a similar question to yours and I named all the steps there

Community
  • 1
  • 1
Coding Enthusiast
  • 3,865
  • 1
  • 27
  • 50