Twitter Bootstrap3 - Make accordion expand on another page when clicking a link

I asked a question about how to extend the accordion to a link:

Twitter Bootstrap 3 - Auto Expand Accordion When Clicking Link In Another Accordion

For which I got the solution, but now I have a different problem, how do I expand the accordion on another page by clicking a link on another page.

I tried various ways as below, none works:

 1. <a class="collapsed" href="[PATH NAME]/#" data-toggle="collapse"
 2. <a class="collapsed" href="#" data-toggle="collapse"
    data-target="[PATH NAME]/#collapseTwo">Test</a>
 3. <a class="collapsed" href="[PATH NAME]" data-toggle="collapse"
    data-target="[PATH NAME]/#collapseTwo">Test</a>



source to share

1 answer

This answer here answers your question:

Bootstrap Collapse - Open the given snippet id

Put EITHER in jQuery or JS

// === opens a collapse from a url
location.hash && $(location.hash + '.collapse').collapse('show');


OR - not both

// === opens a collapse from a url
var anchor = window.location.hash.replace("#", "");
$(".collapse").collapse('hide'); // REMOVE THIS it and it will work more smoothly
$("#" + anchor).collapse('show');


The latter requires a download function. $(document).ready(function() { ... });

Then connect to the folded UNIQUE section as usual for the binding:

<a href="thepage.html#uniqueID">Link text</a>




All Articles