My 'about' page uses a div content switch method (by Bill Posters) that allows me to put the mission, contact, etc, in the same container. It works really well until I try to link into a specific tab from another page. E.g., I have '/about/#mission' or '/about/#contact' that ends up linking to the first 'about' option of the content switch box rather than the correct option. I'd like a user to be able to click on 'Contact Us' from the homepage and get directed straight to the contact tab.
I've tried and tried to tweak the html and the jquery (even experimented with double anchors which I'm pretty sure is not a thing), I've added cookie recognition (doesn't quite work if the user hasn't accessed the page yet...), and I've searched forums extensively. Any ideas what I'm doing wrong or if there's a better way to do this? I'm guessing I'm making the issue much more complicated than necessary, but I'm pretty new to coding and, among other things, may not be using the correct search language.
I'd really appreciate any help!! I'm not married to this particular content switch method and am happy to try something else. Thanks very much!
Sara
function switchContent(obj) {
obj = (!obj) ? 'sub1' : obj;
var contentDivs = document.getElementById('container').getElementsByTagName('div');
for (i=0; i<contentDivs.length; i++) {
if (contentDivs[i].id && contentDivs[i].id.indexOf('sub') != -1) {
contentDivs[i].className = 'hide';
}
}
document.getElementById(obj).className = '';
}
<div id="container">
<div id="sub1">content 1</div>
<div id="sub2" class="hide">content 2</div>
<div id="sub3" class="hide">content 3</div>
<div id="navigation">
<a href="#" class="mininav" onclick="switchContent('sub1'); return false;">link 1</a>
<a href="#" class="mininav" onclick="switchContent('sub2'); return false;">link 2</a>
<a href="#" class="mininav" onclick="switchContent('sub3'); return false;">link 3</a>
</div>