Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between style hidden, block and none

Tags:

javascript

I am trying to find out the differences between style

  • hidden
  • block
  • none

I am trying with this example, but unfortunately this isn't working. Could anybody please let me know the answer?

<html>
<head>
  <title>JavaScript Unleashed</title>

<script>
  function callMe()
  {

  document.getElementById('layer1').style.visibility = 'block';
  }

  </script>
</head>
<body onload="callMe()">


  <div name="layer1">

  <hr>DIV 1<hr>

  </div>




</body>
</html>

1 Answers

You're really close. Two different properties.

display: (block || none) (there are more options here)
visibility: (visible || hidden)

The different is with display:none the element is completely hidden from the view. So if you have a box with 300px height and width then you would not see anything there.

With visibility:hidden it will keep the dimensions of the area, but will hide all the content.

like image 137
Seth Avatar answered Mar 08 '26 07:03

Seth