I have a seemingly simple dropdown menu with some sub-menus. My problem is that I can open the dropdown submenu (the “my dropdown li”'s) but when I got to click on any of them it hides the submenu and goes back to the main menu (home, about, contact). How to I allow the submenu to be closed when clicking on “home” again (which is working), but NOT when I click on the sub-menu items???
I am by all means the most newest of javascript users so I don’t really know where to start.
HTML
<ul id="nav">
<li class="dropdown"><a href="#">Home</a>
<ul>
<li><a href="#">My Dropdown li</a></li>
<li><a href="#">My Dropdown li 2</a></li>
<li><a href="#">My Dropdown li 3</a></li>
</ul>
</li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
JAVASCRIPT
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
$('li.dropdown').click(function() {
$('li.dropdown').not(this).find('ul').hide();
$(this).find('ul').toggle();
});
</script>