CALLBACK FUNCTIONS

Callback functions and advanced event handlers

Some examples of usage of event handler and callback functions to manage animations and graphic effects.

jQuery offers a general syntax:


$('#element_id').doSomething(function() {
	// Implementation of the event handler or callback function
}) ;

which is used to implement both event handler functions, both callback functions.

In this page we use this syntax first to define an event handler for the hover event, in order to invoke the toggleClass() method to switch CSS class (instead of the longer solution coded here). Then we use the same syntax to define a callback for the slideDown() and animate() functions, in order to define a function to be "called back" when the animation ends.

For more details about the callback paradigma, see the advanced tutorial.

See the HTML source for details.

Click on the button below to discover the final question:

The answer to Life, Universe and Everything

Sources

HOME