Friday, May 24, 2024
 Popular · Latest · Hot · Upcoming
135
rated 0 times [  142] [ 7]  / answers: 1 / hits: 29174  / 12 Years ago, fri, august 17, 2012, 12:00:00

I'm using twitter-Bootstrap 2.04, and I'm using the latest jQuery.
I'm trying to make a link that will go from one page to the page containing this accordion, and then activate the appropriate accordion section.
This is the accordion:



 <div class=accordion-group>
<div class=accordion-heading>
<a name=Alink1 class=accordion-toggle data-toggle=collapse data-parent=#accordion2 href=#collapseOne>
<strong>Title</strong>
</a>
</div>
<div id=collapseOne class=accordion-body in collapse style=height: auto; >
<div class=accordion-inner>
some random content
<div>
</div>
</div>
<div class=accordion-group>
<div class=accordion-heading>
<a name=Alink2 class=accordion-toggle data-toggle=collapse data-parent=#accordion2 href=#collapseTwo>
<strong>Title 2</strong>
</a>
</div>
<div id=collapseTwo class=accordion-body collapse style=height: 0px; >
<div class=accordion-inner>
some random content 2
<div>
</div>
</div>


This is the link:



  <a href=page.html/#Alink2>Link to some interesting stuff</a>


With linking to just a bit in the page works fine usually, do I need to use Javascript to activate it?


More From » jquery

 Answers
1

Yes, you will need to manually activate it on page load. Something like the following should work:



$(document).ready(function () {
location.hash && $(location.hash + '.collapse').collapse('show');
});


Also, as @SaadImran pointed out, this assumes that you link to the collapsible element id (eg., #collapseTwo) rather than the name in the anchor (eg., #Alink2).


[#83575] Thursday, August 16, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
damiondenzelc

Total Points: 268
Total Questions: 116
Total Answers: 116

Location: North Korea
Member since Tue, Jun 16, 2020
4 Years ago
damiondenzelc questions
Tue, Nov 24, 20, 00:00, 4 Years ago
Thu, Oct 1, 20, 00:00, 4 Years ago
Wed, Apr 15, 20, 00:00, 4 Years ago
;