JQUERY:
<script type="text/javascript">
$(document).ready(function() {
$('li.directory > ul').css('display','none');
$('li.directory').click(function () {
$(this).toggleClass('expanded');
$('ul', this).slideToggle('slow');
});
});
</script>
HTML: markup fixed now for demo
<ul>
<li class="directory"><a href="#">Parent Link</a>
<ul>
<li><a href="#">Sibling Link</a></li>
<li><a href="#">Sibling Link</a></li>
<li><a href="#">Sibling Link</a></li>
</ul>
</li>
<li class="directory"><a href="#">Parent 2 Link</a>
<ul>
<li><a href="#">Sibling Link</a></li>
<li><a href="#">Sibling Link</a></li>
<li><a href="#">Sibling Link</a></li>
</ul>
</li>
</ul>
This reads to me: When the document is ready, hide any UL with a parent LI of class "directory". If an LI with class "directory" is clicked, add the "expanded" class (display:block), and slideToggle the child UL in to view.
If the LI.directory is clicked again, hide the child UL again.
This works fine. For some reason, this slide behaviour is applied when I click the sibliing LIs. My JQUERY (I believe) is selecting only LIs with a class of directory? So why should class-less LIs be affected.
I'm creating like an interactive document tree and it works fine except for the child LIs firing the SlideToggle event.
Any ideas?
Thanks!