Hiding a button in Javascript

dualCore picture dualCore · Dec 31, 2011 · Viewed 232.4k times · Source

In my latest program, there is a button that displays some input popup boxes when clicked. After these boxes go away, how do I hide the button?

Answer

Philippe picture Philippe · Dec 31, 2011

You can set its visibility property to hidden.

Here is a little demonstration, where one button is used to toggle the other one:

<input type="button" id="toggler" value="Toggler" onClick="action();" />
<input type="button" id="togglee" value="Togglee" />

<script>
    var hidden = false;
    function action() {
        hidden = !hidden;
        if(hidden) {
            document.getElementById('togglee').style.visibility = 'hidden';
        } else {
            document.getElementById('togglee').style.visibility = 'visible';
        }
    }
</script>