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

jQuery Callback method

jQuery Callback method


The callback function executes after the current animation is 100% complete.


The problem with jQuery animations

Many jQuery functions involve animation. These functions may take speed or duration as an optional parameter.

Example:$("p").hide("slow")

speed or duration The parameter can be set to many different values, such as "slow", "fast", "normal" or milliseconds.

Example

The following example runs the callback after the hide effect is fully complete:

Using the callback example

$

(

"

button

"

)

.

click

(

function

(

)

{

$

(

"

p

"

)

.

hide

(

"

slow

"

,

function

(

)

{

alert

(

"

The paragraph is now hidden

"

)

;

}

)

;

}

)

;

Try it

The following example has no callback; the alert box pops up before the hide effect completes:

Without callback

$

(

"

button

"

)

.

click

(

function

(

)

{

$

(

"

p

"

)

.

hide

(

1000

)

;

alert

(

"

The paragraph is now hidden

"

)

;

}

)

;

Online example »