How can I link to a specific section of my 'accordion'?
Hi there,
I have written the following code, which is kind of like an accordion, except that you can open more than one section at once.
jquery code
-
<script type="text/javascript">
jQuery(document).ready(function(){
$(".question").click(function() {
$(this).next().toggle("medium");return false;
}).next().hide();
$(".expand_all").click(function() {
$(".question").next().show("medium");return false;
});
$(".collapse_all").click(function() {
$(".question").next().hide("medium");return false;
});
$(".question").hover(
function () {
$(this).addClass("question_hover");
},
function () {
$(this).removeClass("question_hover");
}
);
$(".answer").append('<p class="close"><a href="#">Collapse</a></p>');
$(".close").click(function () {
$(this).parent().hide("medium");
return false;
});
});
</script>
html code
-
<div class="accordion">
<p><span class="expand_all"><a href="#">expand all</a></span> | <span class="collapse_all"><a href="#">collapse all</a></span></p>
<p class="question"><a href="#hunter">Why did the hunter climb the tree?</a></p>
<div class="answer">
<p>Because he had a bear behind!</p>
</div><!--end answer-->
<p class="question"><a href="#online">You know you've been online too long when...</a></p>
<div class="answer">
<p>As your car crashes through the guardrail on a mountain road, your first instinct is to search for the "back" button</p>
</div><!--end answer-->
</div><!--end accordion-->
I would like to be able to link to a specific section of the accordion from a separate page and for that section to open (e.g. I might like to link to
www.website.com/accordion.html#hunter
and for the section with that anchor tag to open).
Are there any folks out there brainier than me who can suggest how to achieve this?
Many thanks,
Katie