I have a simple ul menu here with nested ul's
I want the nested menu to slide down when the link is clicked and slide up again on the second click. This is working.
I also need any other open nested menus to close when another link is clicked. This isn't working.
I tried to use this to close any open nested menus before I open the nested menu I want but this also closes the nested menu when a link in the nested menu is clicked.
$(document).ready(function () {
$('#nav ul.children').slideUp();
$('#nav li').click(function (e) {
$('ul.children').slideUp();
$('ul', this).slideToggle();
e.stopPropagation();
});
});
http://www.ttmt.org.uk/forum/nav/index2.html
How can I slideToggle the nested menus when it's parent is clicked and close any open nested menus when another link is clicked.
<ul id="nav">
<li><a href="#">One</a>
<ul class="children">
<li><a href="http://www.google.com">One/One</a></li>
<li><a href="http://www.bbc.com">One/Two</a></li>
<li><a href="#">One/Three</a></li>
</ul>
</li>
<li><a href="#">Two</a></li>
<li><a href="#">Three</a>
<ul class="children">
<li><a href="#">Three/One</a></li>
<li><a href="#">Three/Two</a></li>
</ul>
</li>
</ul>
$(document).ready(function(){
$('#nav ul.children').slideUp();
$('#nav li').click(function(e){
//$('ul.children').slideUp();
$('ul', this).slideToggle();
e.stopPropagation();
});
});
EDIT
I have another major problem with my code, because I close the nested ul at the start with
$('#nav ul.children').slideUp();
When a link is clicked and the page reloads the all the menus are closed. How can I keep the nested menu open when the page reloads.