Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference betweet style.visibility and style.display [duplicate]

Tags:

javascript

css

Possible Duplicate:
What is the difference between visibility:hidden and display:none

I am looking at examples to hide/show div tags using JavaScript. In some examples, they use visibility and in some display.

e.g.

document.getElementById("divhotel").style.visibility = "hidden";

vs

document.getElementById("divhotel").style.display = "none";

What is the difference between the two?

like image 378
Maria Velasco Avatar asked Sep 06 '11 22:09

Maria Velasco


2 Answers

When you set visibility to hidden, the element is not shown but still takes up the same space on the page.

When you get display to none, the element is neither shown nor does it take up any space on the page.

More often than not I find myself using display, but it depends on what your scenario demands.

like image 95
Richard Ev Avatar answered Sep 20 '22 23:09

Richard Ev


visibility is how the element is rendered, the block where it exists is still laid out regardless of the value. Items might be pushed around because of that. display is how it is rendered to the page: block is div type elements, with a full box models; none element isn't rendered to the page at all; inline is an inline element such as a span or anchor tag.

like image 44
Travis Avatar answered Sep 24 '22 23:09

Travis