Easy Tutorial
❮ Traversing Has Html Attr ❯

jQuery Callback Method


The Callback function executes after the current animation completes 100%.


Issues with jQuery Animations

Many jQuery functions involve animations. These functions may take speed or duration as optional parameters.

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

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

Example

The following example uses a callback function after the hide effect is fully completed:

Callback Example

$("button").click(function(){
  $("p").hide("slow",function(){
    alert("The paragraph is now hidden");
  });
});

The following example does not use a callback function, and the alert box pops up before the hide effect is completed:

Without Callback

$("button").click(function(){
  $("p").hide("slow");
  alert("The paragraph is now hidden");
});
❮ Traversing Has Html Attr ❯