callbacks.add()S2C 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
callbacksA function, or array of functions, to be added to the specified callback list.Array

Return

undefined

callbacks.add( callbacks ) ExampleTop

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.

Press the button below to action the above code: