Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does jQuery show/hide use display:none instead of visibility:hidden?

display:none means that the element isn't rendered as part of the DOM, so it's not loaded until the display property changes to something else.

visibility:hidden loads the element, but does not show it.

Why does jQuery use display:none for its show/hide functions instead of switching between visibility:hidden and visibility:visible?

like image 751
isayno Avatar asked Jul 21 '09 16:07

isayno


People also ask

Should I use display none or visibility hidden?

visibility: hidden preserve the space, whereas display: none doesn't preserve the space. Show activity on this post. visibility:hidden will keep the element in the page and occupies that space but does not show to the user. display:none will not be available in the page and does not occupy any space.

What is the difference between visibility hidden and display none }?

visibility: hidden hides the element, but it still takes up space in the layout. display: none removes the element completely from the document. It does not take up any space, even though the HTML for it is still in the source code.

How can use visibility hidden in jQuery?

invisible = function() { return this. each(function() { $(this). css("visibility", "hidden"); }); }; $.

Is jQuery hide () is equivalent to?

jQuery hide() Method The hide() method hides the selected elements. Tip: This is similar to the CSS property display:none. Note: Hidden elements will not be displayed at all (no longer affects the layout of the page).


1 Answers

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().

like image 93
Salty Avatar answered Oct 06 '22 00:10

Salty