Reputation: 97
I've got simply javascript to toggle submenu. But there's a problem. I just want to see one submenu at once. How can I fix it?
<script type="text/javascript">
$(document).ready(function() {
$(".nav > li").click(function(){
$(this).children('.submenu').css("margin-left", "0").toggle();
});
});
</script>
Upvotes: 0
Views: 100
Reputation: 321
First close all the submenu opened, then show only the submenu of the menu clicked: Like this
$(".nav > li").click(function(){
('.submenu').hide();
$(this).children('.submenu').css("margin-left", "0").show();
});
Upvotes: 0
Reputation: 14575
This should work:
$('.submenu').hide(); // hide all submenu's
$(this).children('.submenu').show(); // show the one you clicked
Upvotes: 2