I'm currently working on creating a submenu dropdown and following this reference link:
https://www.w3schools.com/bootstrap/tryit.asp?filename=trybs_ref_js_dropdown_events2&stacked=h
However, I am facing an issue where all my submenus are always open. I want them to operate normally, where the submenu will only appear when I hover over the parent menu. I am using Bootstrap 3.3.7.
Referencing the image provided below, even when I press the "CLICK" button, the submenus remain constantly open (menu 3 and menu 4) https://i.sstatic.net/BVCF0.png
This is the code snippet in question:
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">CLICK
<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#">MENU 1</a></li>
<li><a tabindex="-1" href="#">MENU 2</a></li>
<li class="dropdown-submenu">
<a class="test" tabindex="-1" href="#">MENU 3</a>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#">MENU 3.1</a></li>
<li><a tabindex="-1" href="#">MENU 3.2</a></li>
</ul>
</li>
<li class="dropdown-submenu">
<a class="test" tabindex="-1" href="#">MENU 4</a>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#">MENU 4.1</a></li>
<li><a tabindex="-1" href="#">MENU 4.2</a></li>
</ul>
</li>
</ul>
</div>
// style
.dropdown-submenu {
position: relative;
}
.dropdown-submenu>.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
-webkit-border-radius: 0 6px 6px 6px;
-moz-border-radius: 0 6px 6px;
border-radius: 0 6px 6px 6px;
}
.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
.dropdown-submenu>a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #ccc;
margin-top: 5px;
margin-right: -10px;
}
.dropdown-submenu:hover>a:after {
border-left-color: #fff;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left>.dropdown-menu {
left: -100%;
margin-left: 10px;
-webkit-border-radius: 6px 0 6px 6px;
-moz-border-radius: 6px 0 6px 6px;
border-radius: 6px 0 6px 6px;
}