jQuery callbacks.add()Method

jQuery 杂项方法jQuery Miscellaneous Methods

Examples

Add functions to the callback list

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

Try it Yourself »

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 the callback list to which it is bound.


Syntax

callbacks.add( callbacks )

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


jQuery 杂项方法jQuery Miscellaneous Methods

Other Extensions