Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
21
rated 0 times [  27] [ 6]  / answers: 1 / hits: 24652  / 12 Years ago, fri, november 16, 2012, 12:00:00

Imagine a Bootstrap collapse with 3 parts



<div class=panel-group id=accordion>
...
<div id=accordionOne class=panel-heading></div>
...
<div id=accordionTwo class=panel-heading></div>
...
<div id=accordionThree class=panel-heading></div>
</div>


Is there a simple way to make the plugin open the given HTTP fragment identifier ?



Example http://myproject/url#accordionTwo would open the second accordion


More From » html

 Answers
111
$(#accordionTwo).collapse('show');


To open the given HTTP fragment identifier, try this:



$(document).ready(function() {
var anchor = window.location.hash;
$(.collapse).collapse('hide');
$(anchor).collapse('show');
});


EDIT:



As pointed by bart in the comments:
be careful with targeting .collapse because this class is also used for the navigation bar when the viewport is xs.


[#81963] Wednesday, November 14, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
braydon

Total Points: 0
Total Questions: 102
Total Answers: 111

Location: Sao Tome and Principe
Member since Wed, Dec 29, 2021
2 Years ago
;