I want to hide a div (switch) and show another div (hiddenonload) when the button is pressed. I've managed to hide the switch div on press but how do I show the hiddenonload div, when the button is pressed?
My code
var button = document.querySelector("button");
var element = document.querySelector(".switch");
button.addEventListener("click", function() {
element.classList.toggle("hide");
});
.switch {
opacity: 1;
}
.switch.hide {
opacity: 0;
}
.hiddenonload {
display: none;
}
<div class="switch">
<button>
<a>Hide me on click</a>
</button>
</div>
<div class ="hiddenonload">
<p>Show me</p>
</div>