The jQuery callback function solves a very common problem when dealing with animation. JavaScript statements are executed line by line. There are instances when working with animations, where you do not want the next line of code to be executed until the animation has been completed. To prevent this from happening, you can use the callback function.
Syntax
$(selector).effect(speed,callback)
HTML Example
We will use the following HTML for the examples listed below.
;Example
In the following examples, we will look at the difference between using the callback function and omitting the callback function. In the first example, no callback function is used. Notice that the toggle image changes before the animation is completed.
In the second example, the callback function is used and the toggle image is not modified until the animation is completed.