html – Hiding a button in Javascript

html – Hiding a button in Javascript

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

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

is very useful, but it will still take up space on the page. You can also use


because that will not only hide the object, but make it so that it doesnt take up space until it is displayed. (Also keep in mind that displays opposite is block, not visible)

html – Hiding a button in Javascript

Something like this should remove it


If you are going to do alot of this dom manipulation might be worth looking at jquery

Leave a Reply

Your email address will not be published.