I am still fairly new to jQuery so the following may seem pretty basic to many of you.
I am working on an accordion navigation that uses jQuery (but I am not using jQuery UI). The page is here: http://www.rouviere.com/nav/index.html
Here is the HTML:
<div id="subContent">
<ul>
<li><a href="nikon.html">Nikon</a></li>
<li class="cameras"><a href="#" class="drop">Cameras</a>
<ul>
<li><a href="nikon-d3x.html">Nikon D3x</a></li>
<li><a href="nikon-d3s.html">Nikon D3s</a></li>
<li><a href="nikon-d700.html">Nikon D700</a></li>
<li><a href="nikon-d300s.html">Nikon D300s</a></li>
</ul>
</li>
<li class="lenses"><a href="#" class="drop">Lenses</a>
<ul>
<li><a href="24-70.html">Nikkor 24-70 f2.8</a></li>
<li><a href="80-200.aspx">Nikkor 80-200 f2.8</a></li>
<li><a href="300.html">Nikkor 300 f2.8</a></li>
<li><a href="50.html">Nikkor 50 f1.4</a></li>
</ul>
</li>
<li class="bags"><a href="#" class="drop">Bags</a>
<ul>
<li><a href="bag1.html">Small Bag</a></li>
<li><a href="bag2.html">Medium Bag</a></li>
<li><a href="bag3.html">Large Ba</a></li>
</ul>
</li>
<li><a href="#" class="drop">Memory Cards</a></li>
</ul>
</div>
Here is the jQuery:
<script type="text/javascript">
$(function(){
$('.interior #subContent > ul > li > a.drop').click(function(){
$(this).parent().children('ul').toggle("slow");
return false;
});
$(window).ready(function() {
$('li.cameras ul').hide();
$('li.lenses ul').hide();
$('li.bags ul').hide();
});
});
</script>
The page displays with the ul li ul all collapsed, however, they don’t toggle open when you click on the parent links.
I would appreciate a seasoned eye or two to review this and help me figure out what is missing.
Thanks!
Shorter way to write it:
$(window).ready()is meaningless. I’m suprised it did anything before.A more meaningful and expandable way to write it would probably be this: