I have successfully created a navigation menu, but I am facing an issue where the menu remains open until the mouse moves out of the dropdown.
I already have a function in place that displays content in another <div>
(otherDiv) when an item is selected from the menu. Now, I want this function to also hide the menu simultaneously.
function go(obj) {
var page = obj.href;
document.getElementById('otherDiv').innerHTML = '<img src="' + page + '"></img>'
return false;
document.getElementById('menu1').style.display = "none";
document.getElementById('menu2').style.display = "none";
document.getElementById('menu3').style.display = "none";
document.getElementById('menu4').style.display = "none";
document.getElementById('menu5').style.display = "none";
document.getElementById('menu6').style.display = "none";
}
.drpbtn {
display: inline-block;
color: #ffffff;
text-align: center;
padding: 12px 25px;
list-style-type: none;
width: auto;
margin: 0;
background-color: #403e3e;
color: #ffffff;
float: left;
font-family: arial;
font-size: 14px;
}
.drpbtn:hover {
background-color: #00b3be;
}
.drpbtn:hover .dropdown-content {
display: inline-block;
}
.dropdown-content {
display: none;
list-style-type: none;
position: absolute;
background-color: #fafafa;
width: 290px;
color: #000000;
text-align: left;
margin-left: -4.7em;
margin-top: 0.89em;
}
.dropdown-content li:hover {
background-color: #e1e1e1;
}
.dropdown-content li {
display: block;
}
.li-drop {
display: inline-block;
color: #000000;
text-align: left;
padding: 11px 13px;
text-decoration: none;
margin: auto;
}
<div id="menu">
<ul>
<li class="drpbtn">Menu 1
<ul id="menu1">
<div class="dropdown-content">
<li class="li-drop">
<a href="url" onclick="return go(this);">
<div class="div-drop">Choice 1</div>
</a>
</li>
<li class="li-drop">
<a href="url" onclick="return go(this);">
<div class="div-drop">Choice 2</div>
</a>
</li>
<li class="li-drop">
<a href="url" onclick="return go(this);">
<div class="div-drop">Choice 3</div>
</a>
</li>
</div>
</ul>
</li>
<li class="drpbtn">Menu 2
<ul id="menu2">
<div class="dropdown-content">
<li class="li-drop">
<a href="url" onclick="return go(this);">
<div class="div-drop">Choice 1</div>
</a>
</li>
<li class="li-drop">
<a href="url" onclick="return go(this);">
<div class="div-drop">Choice 2</div>
</a>
</li>
<li class="li-drop">
<a href="url" onclick="return go(this);">
<div class="div-drop">Choice 3</div>
</a>
</li>
</div>
</ul>
</li>
<li class="drpbtn">Menu 3
<ul id="menu3">
<div class="dropdown-content">
<li class="li-drop">
<a href="url" onclick="return go(this);">
<div class="div-drop">Choice 1</div>
</a>
</li>
<li class="li-drop">
<a href="url" onclick="return go(this);">
<div class="div-drop">Choice 2</div>
</a>
</li>
<li class="li-drop">
<a href="url" onclick="return go(this);">
<div class="div-drop">Choice 3</div>
</a>
</li>
</div>
</ul>
</li>
</ul>
</div>
I need assistance with resolving this issue. Can you help?