Easy Tutorial
❮ Css Width Traversing Offsetparent ❯

jQuery callbacks.add() Method

jQuery Miscellaneous Methods

Example

Add functions to the callback list

$(function () { 
    var foo = function( value ) {
          alert( "foo: " + value );
    };
    // Another function to be added to the list
    var bar = function( value ){
          alert( "bar: " + value );
    };     
    var callbacks = $.Callbacks();     
    // Add function "foo" to the list
    callbacks.add( foo );     
    // Invoke all callbacks in the list with the given arguments
    callbacks.fire( "hello" );
    // Output: "foo: hello"     
    // Add function "bar" to the list
    callbacks.add( bar );     
    // Invoke all callbacks in the list with the given arguments
    callbacks.fire( "world" );     
    // Output:
    // "foo: world"
    // "bar: world"
})

Definition and Usage

The callbacks.add() function is used to add a callback or a collection of callbacks to the callback list.

Tip: This method returns a callback object to its bound callback list.


Syntax

Parameter Description
callbacks Function, Array type A function or an array of functions to add to the callback list

jQuery Miscellaneous Methods

❮ Css Width Traversing Offsetparent ❯