JavaScript codes are executed line by line. However, the next line of the code can run even though the effect of the first line of code is not finished. This can create errors.
To prevent this errors, we can create a callback function. callback function will minimize the error that is affected during current effects. A callback function is executed after the effects is finished of the last line code.
The example below has a callback parameter that is a function that will be executed after the hide effect is completed:
$("button").click(function(){
$("p").hide("slow", function(){
alert("The paragraph is now hidden");
});
});
The below code has no callback parameter and alert box will be displayed before the hide effect is completed
Example without Callback-
$("button").click(function(){
$("p").hide(1000);
alert("The paragraph is now hidden");
});
0 Comment(s)