Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does jQuery implement hide() and show()

Tags:

jquery

css

Do they set display: none or visibility: hidden?

I'm pretty sure display: none takes the element out of the normal flow, whilst visibility: hidden just hides the element but still has a reserved space for it.

Should I just go download the unpacked version and study it or does someone have a quick answer?

like image 271
alex Avatar asked Oct 27 '08 06:10

alex


People also ask

How does jQuery show hide work?

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). Tip: To show hidden elements, look at the show() method.

How do you do show hide in jQuery?

Syntax: $(selector). hide(speed,callback);

What does show () do in jQuery?

The show() Method in jQuery is used to display the hidden and selected elements. Note: This method display the hidden elements which are using CSS display: none property. The elements are not visible whose visibility is hidden.

Which jQuery function is a combination of hide () and show ()?

jQuery toggle() method is used to change the to display or hide HTML elements. By combining this method with toggle, we made it so clicking the same button can make the item that appears disappear when the button is clicked once again.


2 Answers

It uses display, and for this type of thing you can use Firebug to actually examine what happens to the DOM.

like image 45
Parand Avatar answered Oct 06 '22 00:10

Parand


It uses display.

Edit: And from John Sheehan's comment on this answer, which I agree with:

You should go view the unpacked source anyway just to familiarize yourself with it

Edit 2: Comments have mentioned using Firebug to discover what is happening. Indeed, I actually went to the jQuery docs and used the Safari Web Inspector to see what happened on the hide() demo to be sure of my answer.

like image 115
eyelidlessness Avatar answered Oct 06 '22 00:10

eyelidlessness