Reputation: 4998
I was working on sidebar navigation(using bootstrap). But I got stuck here. I am not able to toggle the child menu . All I need to hide the child menu when I clicked on the top menu such as Main,Next Section and Third Section. For eg when I click on the Main menu it has to hide all the child dashboard and click on Next section menu has to hide all sample section .
Any help highly appreciable
This is the structure
<ul class="nav nav-tabs nav-stacked main-menu">
<li class="nav-header">Main</li>
<li><a href='#'>Dashboard</a></li>
<li><a href='#'>Dashboard</a></li>
<li><a href='#'>Dashboard</a></li>
<li><a href='#'>Dashboard</a></li>
<li class="nav-header">Next Section</li>
<li><a href='#'>Sample Section</a></li>
<li><a href='#'>Sample Section</a></li>
<li><a href='#'>Sample Section</a></li>
<li><a href='#'>Sample Section</a></li>
<li class="nav-header">Third Section</li>
<li><a href='#'>Third Sample Section</a></li>
<li><a href='#'>Third Sample Section</a></li>
<li><a href='#'>Third Sample Section</a></li>
<li><a href='#'>Third Sample Section</a></li>
</ul>
Upvotes: 0
Views: 1835
Reputation: 13586
$(document).ready(function(){
$('li.nav-header').click(function(){
$(this).nextUntil('li.nav-header').toggle();
});
});
Upvotes: 2
Reputation: 362360
You can use jQuery .nextUntil()
like this..
$('.nav-header').click(function () {
$(this).nextUntil('.nav-header').toggle(200);
});
Demo: http://bootply.com/67126
Upvotes: 3