r/HTML • u/EillaSocks • 13h ago
Question How to show and hide an html button
After some Googling, I haven't been able to find what I needed, so I'm turning to y'all. Thanks in advance for your help(:
I am making a clicker game in html/css/js. Right now, I have working 'buttons' by using <div> like this:
<div id="addPebbleId" onclick="pebbleFunction()">Collect Pebble (+1 Pebble)</div>
I can easily hide the div 'buttons' by using the id. So far, so good, right?
The problem is, even with div, the buttons look like normal text. So, I figured I'd make them actual buttons, so that it's obvious you should click on them.
<button> <div id="addPebbleId" onclick="pebbleFunction()">Collect Pebble (+1 Pebble)</div> </button>
It works great when the button is visible. The issue is when the button is hidden via js, like this:
x = document.getElementById("addPebbleId");
x.style.display = "none";
There's still a tiny blank button visible, even if the text is hidden. I know you can hide buttons in html with <button hidden> but how do I code it to show or hide the button later on?
3
u/vbfischer 13h ago