I'm trying to create an onclick
div
. I have a simple problem, but I don't know how to solve it, because I'm still new to javascript.
My div
is showing when I load the page. I want it to not show until it is toggled.
I imagine this is a simple change in the php.
Thank you.
function myFunction() {
var x = document.getElementById("onclickmenu");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
#onclickmenu {
width: 100%;
padding: 50px 0;
text-align: center;
background-color: lightblue;
margin-top: 20px;
}
<button onclick="myFunction()">Menu</button>
<div id="onclickmenu">
<p> hej</p>
</div>