So I have it working like this:
Copyright 2007 by Marco van Hylckama Vlieg
web: http://www.i-marco.nl/weblog/
email: marco@i-marco.nl
Free for non-commercial use
*/
function initMenu() {
var hash = window.location.hash.substring( 1 );
$('#menu ul').hide();
$('#menu li a').click(
function() {
$('#menu ul').hide('normal');
$(this).next().slideToggle('normal');
}
);
if( hash ) {
var accordItem = $('#menu li a#' + hash);
if(accordItem) accordItem.next().slideToggle('normal');
}
}
$(document).ready(function() {initMenu();});
...but it is not working like this:
function accord() {
var hash = window.location.hash.substring( 1 );
$(".accordion div").hide();
$(".accordion h3").click(function(){
$(this).next("div").slideToggle("fast")
.siblings("div:visible").slideUp("fast");
$(this).toggleClass("active");
$(this).siblings("h3").removeClass("active");
});
if(hash) {
var accordItem = $('.accordion h3 a#' + hash);
if(accordItem) accordItem.next('div').show();
}
}
$(document).ready(function() {accord();});
What is the difference? My accordion is coded like this:
<div class="accordion">
<h3><a href="#">Computer Software</a></h3>
<div>
<ul>
<li><a href="computer-software.php#software-1">Software 1</a></li>
<li><a href="computer-software.php#software-2">Software 2</a></li>
</ul>
</div>
...........................
</div>
I used firebug and can see that accordItem is getting the correct HASH, but when I tell it to toggle the 'div' it doesn't. What am I missing here?
Thanks!