javascripthtmlbuttonhide

Hiding a button in Javascript


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?


Solution

  • 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>