Why does jQuery show/hide use display:none instead of visibility:hidden?
Because in display:none
, the element, for all purposes, ceases to exist -- it doesn't occupy any space.
However, in visibility:hidden
, it's as if you had just added opacity:0
to the element -- it occupies the same amount of space but just acts invisible.
The jQuery creators probably thought the former would be a better fit for .hide()
.
visibility: hidden
makes an element invisible but does not remove it from the layout of the page. It leaves an empty box where the element was. display: none
removes it from the layout so it doesn't take up any space on the page, which is usually what people want when they hide something.