Currently, I am in the process of setting up an onclick dropdown navigation bar for the mobile version of my website. However, I am facing an issue where it requires a double click in order for the dropdown to activate. What I actually want is for it to drop down with just one click.
So far, the only solution I have attempted is using a JavaScript function that I will include in my code snippet below.
function myFunction() {
var x = document.getElementById("submenu1");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
function myFunction_2() {
var y = document.getElementById("submenu2");
if (y.style.display === "none") {
y.style.display = "block";
} else {
y.style.display = "none";
}
}
.main-nav {
display: flex;
}
/* CSS code continues here */
After implementing this code, I expected the dropdown menu to respond to a single click. Unfortunately, the current behavior is such that it requires two clicks, which is not what I intended.
If anyone could provide assistance and help me achieve the desired functionality, it would be greatly appreciated. Thank you in advance.