Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery Effects – Hide and Show

jQuery Effects - Hide and Show


Hide, show, toggle, slide, fade, and animate - wow!

Click to Show/Hide Panel

Because time is precious, we provide a quick and convenient way to learn.

At Runoob Tutorial, you can learn what you need.


Example

jQuery hide()
A simple demonstration of the jQuery hide() method.

jQuery hide()
Another hide() example. Demonstrates how to hide text.


jQuery hide() and show()

With jQuery, you can use the hide() and show() methods to hide and show HTML elements:

Example

$

(

"

#hide

"

)

.

click

(

function

(

)

{

$

(

"

p

"

)

.

hide

(

)

;

}

)

; $

(

"

#show

"

)

.

click

(

function

(

)

{

$

(

"

p

"

)

.

show

(

)

;

}

)

;

Try it »

Syntax:

$(

selector

).hide(

speed,callback

);

$(

selector

).show(

speed,callback

);

The optional speed parameter specifies the speed of hiding/showing and can take the following values: "slow", "fast", or milliseconds.

The optional callback parameter is the name of the function to be executed after hiding or showing completes.

The following example demonstrates the hide() method with a speed parameter:

Example

$

(

"

button

"

)

.

click

(

function

(

)

{

$

(

"

p

"

)

.

hide

(

1000

)

;

}

)

;

Try it »

The following example demonstrates the hide() method with a speed parameter and a callback function:

Example

$

(

document

)

.

ready

(

function

(

)

{

$

(

"

.hidebtn

"

)

.

click

(

function

(

)

{

$

(

"

div

"

)

.

hide

(

1000

,

"

linear

"

,

function

(

)

{

alert

(

"

The hide() method is complete!

"

)

;

}

)

;

}

)

;

}

)

;

Try it »

The second parameter is a string indicating which easing function to use for the transition. (Translator's note: jQuery itself provides "linear" and "swing"; others can be used via related plugins.)


jQuery toggle()

With jQuery, you can use the toggle() method to switch between the hide() and show() methods.

Show hidden elements and hide displayed elements:

Example

$

(

"

button

"

)

.

click

(

function

(

)

{

$

(

"

p

"

)

.

toggle

(

)

;

}

)

;

Try it »

Syntax:

$(

selector

).toggle(

speed,callback

);

The optional speed parameter specifies the speed of hiding/showing and can take the following values: "slow", "fast", or milliseconds.

The optional callback parameter is the name of the function to be executed after hiding or showing completes.