Table of Contents
What is a Callback Function in jQuery?
A Callback function is nothing but a jQuery function, which will be executed once the effect is complete.
A callback function is called as a higher-order function that can be passed to another function as a parameter. That callback function will be executed inside the other function. Hence, the use of this callback function is known as the callback pattern. Moreover, it is always appears as the last argument of the method.
Syntax with Callback Function as a Parameter
Here is the basic syntax of the jQuery slideToggle() effect method with a callback function;
Basic Noteworthy Principles for Callback Function
- Try to use anonymous functions as callbacks
- Pass parameters to callback functions
- Check the callback function before executing it
- Try to use Call or Apply function to preserve this object as callbacks
- More than one callback functions permitted
Once you are familiar and understand every nook and corner of a callback function, then you can start making your own callback functions. Because, callback functions are very simple yet powerful to use and they offer amazing features to your web applications and code.