I’m using a jQuery toggle effect from Sohtanaka in order to ‘show’ and ‘hide’ content.
This is the jQuery:
$(document).ready(function(){
//Hide (Collapse) the toggle containers on load
$(".toggle_container").hide();
//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
$("h2.trigger").click(function(){
$(this).toggleClass("active").next().slideToggle("slow");
return false; //Prevent the browser jump to the link anchor
});
});
and this is my HTML:
<h2 class="trigger"><a href="#test1">Test 1</a></h2>
<div class="toggle_container">
<div class="block">
<h3>Content Header</h3>
<p>content</p>
</div>
</div>
<h2 class="trigger"><a href="#test2">Test 2</a></h2>
<div class="toggle_container">
<div class="block">
<h3>Content Header</h3>
<p>content</p>
</div>
</div>
<h2 class="trigger"><a href="#test3">Test 3</a></h2>
<div class="toggle_container">
<div class="block">
<h3>Content Header</h3>
<p>content</p>
</div>
</div>
Everything works as expected.
I’d like to know what needs to be modified so that a specific container is shown when the corresponding anchor is on the end of the url?
e.g. If my url is “www.domain.com/content/#test2” I would like container ‘Test 2’ to be shown and ‘Test 1’ and ‘Test 3’ to remain hidden.
Many thanks.
You should be able to add this functionality to your code like this: