callbacks.add()
JQ Home <<
Objects <<
callbacks.add()
Add to the callbacks list.
Description
The callbacks.add()
Callbacks object method, allows us to add callback(s) to a callback list.
Syntax
Signature | Description |
---|---|
callbacks.add(callbacks) | Add callback(s) to a callback list. |
Parameters
Parameter | Description | Type |
---|---|---|
callbacks | A function, or array of functions, to be added to the specified callback list. | Array |
Return
callbacks.add( callbacks )
Example
Objects << Top
Add callback(s) to a callback list.
In the example below when we press the button the first time we add the aFunc(value, div)
and bFunc(value, div)
functions to our callbacks list and fire them off.
$(function(){
$('#btn6').one('click', function(){
var ourCallbacks = $.Callbacks();
ourCallbacks.add( aFunc );
ourCallbacks.fire( 'The aFunc
function was fired from our callbacks. <br>', '#div6');
ourCallbacks.add( bFunc );
ourCallbacks.fire( 'The bFunc
function was fired from our callbacks. <br>', '#div6');
});
function aFunc( value, div ){
$(div).append( value);
}
function bFunc( value, div ){
aFunc('Passing bFunc
function value to aFunc
. <br>', div);
}
});
div6. Some initial text.
Related Tutorials
jQuery Advanced Tutorials - Lesson 6 - The Callbacks Object