Is there a way to show an element when a button is clicked without the button moving position? When the button is clicked again, the element should disappear.
var element = document.getElementById("element");
function toggleVisibility() {
if (element.style.display == "block") {
element.style.display = "none";
} else {
element.style.display = "block";
}
}
<div id="element" style="display: none;">Content Here</div>
<button onclick="toggleVisibility()">Toggle Element</button>
I have considered moving the button below the element, but that would just cause another issue with a different element being repositioned.