+ 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 Answers
+ 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;
}