jQuery Tutorial
jQuery Introduction jQuery Getting Started jQuery Syntax jQuery Selectors jQuery Events
jQuery Effects
jQuery Hide/Show jQuery Fade jQuery Slide jQuery Animation jQuery stop() jQuery Callback jQuery Chaining
jQuery Manipulation
jQuery Get/Set jQuery Add jQuery Remove jQuery CSS Classes jQuery css() jQuery Dimensions
jQuery Traversing
jQuery Traversing jQuery Ancestors jQuery Descendants jQuery Siblings jQuery Filtering
jQuery AJAX
jQuery AJAX Intro jQuery Load jQuery Get/Post jQuery AJAX Events
jQuery Misc
jQuery noConflict() jQuery Filters
jQuery References
jQuery Reference jQuery Selectors jQuery Events jQuery Effects jQuery HTML/CSS jQuery Traversing jQuery AJAX jQuery Miscellaneous jQuery Properties

jQuery Callback Functions

JavaScript statements are executed line by line. But, since jQuery effect takes some time to finish, the next line code may execute while the previous effect is still running. This can create errors.

To prevent this from happening jQuery provides a callback function for each effect method.

A callback function is executed after the current effect is finished.

The callback function is passed as an argument to the effect methods and they typically appear as the last argument of the method.

Typical syntax: $(selector).hide(duration, easing, callback);

The example below has a callback parameter that is a function that will be executed after the hide effect is completed:

Run code

The example below has no callback parameter, and the alert box will be displayed before the hide effect is completed:

Run code