+ 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?

27th Feb 2019, 10:50 PM
Chaves Dias Jr.
Chaves Dias Jr. - avatar
3 odpowiedzi
+ 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
27th Feb 2019, 11:05 PM
Nathan Lewis
Nathan Lewis - avatar
+ 4
<button onclick='document.getElementById("toHide").style.display="none"'> Hide other button </button> <button id='toHide'>I will disappear</button>
27th Feb 2019, 11:07 PM
KrOW
KrOW - avatar
+ 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; }
28th Feb 2019, 12:19 AM
Calviղ
Calviղ - avatar