Im trying to make a toggle menu, however when i insert a <button>
tag instead of a <p>
tag the whole menu doesn't work, but it works with <p>
.
How can i solve this problem?
Snippet:
function toggleMenu() {
var menuBox = document.getElementById('menu-box');
if (menuBox.style.display == "block") { // if is menuBox displayed, hide it
menuBox.style.display = "none";
} else { // if is menuBox hidden, display it
menuBox.style.display = "block";
}
}
<div id="infobox2">
<form action="index.html" method="get">
<p onclick="toggleMenu()" id="menu"> Skapa konto </p>
<ul id="menu-box" style="display: block">
<li><a href="index.html">Start</a></li>
<li><a href="animal.html">Animal</a></li>
<li><a href="pictures.html">Pictures</a></li>
</ul>
</form>
</div>