+ 1
How to hide and show a button
I have a button on an web page, but I want this button to only be visible after another button is pressed. How can I do it?
3 Respuestas
+ 5
Put the button within another element and give that element an id (“button1”). Set that element’s style to “display: none”. Then, write a function in js with a variable button = document.getElementById(“button1”). Then do, button.style.display = “inline”; when you want it back. Im pretty sure thats the correct syntax! hope it works for ya
+ 4
<button onclick='document.getElementById("toHide").style.display="none"'> Hide other button </button>
<button id='toHide'>I will disappear</button>
+ 3
Safer way is to toggle a button on/off from JavaScript
Js:
var btn = document.querySelector('.btn-to-hide'); btn.classList.toggle('display-none');
Css:
display-none {
display: none! important;
}