I'm having trouble figuring out how to close an element when another element collapses. I've searched for solutions without success.
My structure is updated using Bootstrap and JavaScript, but it doesn't function as expected. Specifically, when collapsing the first sub-menu (
<div class="collapse list-group-sub-menu spacer" id="subMenu1">
), I also want the second sub-menu to collapse. In my project, all divisions are in rows, otherwise, I would have used a different method.
HTML
<div class="container">
<div class="row">
<div class="col-md-6">
<table class="table table-responsive">
<tbody>
<tr>
<td class="col-lg-10">
<div id="bar1">
<div class="list-group panel">
<a class="list-group-item list-group-item-warning">Menu</a>
<!--"collapse in" to keep it open from the start-->
</div>
</div>
</td>
</tr>
</tbody>
</table>
<table class="table table-responsive">
<tr>
<td>
<div class="collapse in" id="sidebar1">
<a href="#subMenu1" onclick="SubMenu()" class="list-group-item" data-parent="#sidebar1" data-toggle="collapse">Item 1 <i class="fa fa-caret-down"></i></a>
<a href="#" class="list-group-item">Item 2</a>
<a href="#" class="list-group-item">Item 3</a>
<a href="#" class="list-group-item">New <i class="fa fa-plus-circle"></i></a>
</div>
</td>
</tr>
</table>
<table class="table table-responsive">
<tr>
<td>
<div class="collapse list-group-submenu spacer" id="subMenu1">
<a href="#" class="list-group-item" data-parent="#subMenu1">Item 1.1</a>
<a href="#" class="list-group-item" data-parent="#subMenu1">Item 1.2</a>
<a href="#subSubMenu1" onclick="SubSubMenu()" class="list-group-item" data-toggle="collapse">Item 1.3 <i class="fa fa-caret-down"></i></a>
<a href="#" class="list-group-item">Item 1.4</a>
<a href="#" class="list-group-item">New <i class="fa fa-plus-circle"></i></a>
</div>
</td>
</tr>
</table>
<table class="table table-responsive">
<tr>
<td>
<div class="collapse list-group-submenu list-group-submenu-1 spacer" id="subSubMenu1">
<a href="#" class="list-group-item">Item 1.3.1</a>
<a href="#" class="list-group-item">Item 1.3.2</a>
<a href="#" class="list-group-item">New <i class="fa fa-plus-circle"></i></a>
</div>
</td>
</tr>
</table>
</div>
<div class="col-md-6">
<table class="table table-responsive">
<tbody>
<tr>
<td class="col-lg-10">
<div id="bar2">
<div class="list-group panel">
<a class="list-group-item list-group-item-warning">Menu</a>
<!--"collapse in" to keep it open from the start-->
</div>
</div>
</td>
</tr>
</tbody>
</table>
<table class="table table-responsive">
<tr>
<td>
<div class="collapse in" id="sidebar2">
<p class="list-group-item" data-parent="#sidebar2">Item 1</p>
<p class="list-group-item">Select
<input type="checkbox" /> </p>
<p class="list-group-item">Select
<input type="checkbox" />
</p>
<a href="#" class="list-group-item">New <i class="fa fa-plus-circle"></i></a>
</div>
</td>
</tr>
</table>
<table class="table table-responsive">
<tr>
<td>
<div class="collapse list-group-submenu" id="subMenu2">
<p class="list-group-item" data-parent="#subMenu2">Select
<input type="checkbox" />
</p>
<p class="list-group-item" data-parent="#subMenu2">Select
<input type="checkbox" />
</p>
<p class="list-group-item">Item 1.3</p>
<p class="list-group-item">Select
<input type="checkbox" />
</p>
<p class="list-group-item">New <i class="fa fa-plus-circle"></i></p>
</div>
</td>
</tr>
</table>
<table class="table table-responsive">
<tr>
<td>
<div class="collapse list-group-submenu list-group-submenu-2" id="subSubMenu2">
<p class="list-group-item">Select
<input type="checkbox" />
</p>
<p class="list-group-item">Select
<input type="checkbox" /> </p>
<p class="list-group-item">New <i class="fa fa-plus-circle"></i></p>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
SCRIPTS
function SubMenu() {
$('#subMenu1').collapse("toggle");
$('#subMenu1').is('collapse', function(){
SubSubMenu();
});
}
function SubSubMenu() {
$('#subSubMenu1').collapse("toggle");
$('#subSubMenu2').collapse("toggle");
}