Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery callbacks.add() method

jQuery callbacks.add() method

jQuery Miscellaneous MethodsjQuery Miscellaneous Methods

Example

Add a function 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 the function "foo" to the list

callbacks

.

add

(

foo

)

;

//

Call all functions in the callback list with the given arguments

callbacks

.

fire

(

"

hello

"

)

;

//

Output: "foo: hello"

//

Add the function "bar" to the list

callbacks

.

add

(

bar

)

;

//

Call all functions in the callback list with the given arguments

callbacks

.

fire

(

"

world

"

)

;

//

Output:

//

"foo: world"

//

"bar: world"

}

)

Try it »


Definition and Usage

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

**Tip:** This method returns the callbacks object to the callback list it is bound to.


Syntax

callbacks.add( callbacks )

Parameters Description
callbacks Function,Array type: a function or an array of functions to be added to the callback list

jQuery Miscellaneous MethodsjQuery Miscellaneous Methods