I have a div I'm hiding behind a button I want to toggle "onpress". I want that div to only be visible when someone presses down on the button layered above it.
I'm only aware of how to use onclick
for toggling visibility. See the snippet.
I simply want a press function that toggles the show/hide of the button above the hidden div.
function myFunction() {
var x = document.getElementById("button1");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
button {
width: inherit;
height: inherit;
}
body {
background-color: black;
}
#button1 {
background-color: rgba(100,100,100,.5);
position: absolute;
width: 50vw;
height: 10vw;
z-index: 1000;
}
#hiddendiv1 {
background-color: orange;
position: absolute;
width: 50vw;
height: 10vw;
display: flex;
align-items:center;
justify-content: center;
z-index: -1000;
}
<div id=button1>
<button onclick="myFunction()">I want to toggle this button div off during "onpress"</button>
</div>
<div id=hiddendiv1>
I want to see this div ONLY when the button is being "pressed" down.
</div>