Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 410
dualCore Avatar asked Dec 30 '11 23:12

dualCore


People also ask

How do I hide a button?

You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <button> is not visible, but maintains its position on the page.

How do I hide an item in JavaScript?

To hide an element, set the style display property to “none”. document. getElementById("element").


2 Answers

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> 
like image 61
Philippe Avatar answered Sep 26 '22 05:09

Philippe


visibility=hidden 

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

display=none 

because that will not only hide the object, but make it so that it doesn't take up space until it is displayed. (Also keep in mind that display's opposite is "block," not "visible")

like image 40
benny.bennett Avatar answered Sep 22 '22 05:09

benny.bennett