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 ac
You can use the position of the accordion section. The following link opens the third accordion section on a twitter bootstrap (wordpress) accordion.
Link Example: http://www.zfp-bauwesen.de/leistungen/ubersicht#3
Javscript Code:
$( document ).ready(function() {
if (window.location.hash) {
var AccordionSectionNumber = window.location.hash.substring(1);
AccordionBodyID = $(".accordion .accordion-group:nth-of-type(" + AccordionSectionNumber + ") .accordion-heading a").attr('href')
if (! (typeof AccordionBodyID === "undefined")) {
$(AccordionBodyID).collapse('show');
return true;
}
}
});
Thanks for your help.
I added functionality so that the code can open Accordions WITHIN Accordions:
$(document).ready(function () {
if (location.hash){
$(location.hash).collapse('show');
$(location.hash).parents('.accordion-body').collapse('show');
}
});
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
).
Have you tried this:
<a href="page.html#Alink2">Link to some interesting stuff</a>