callbacks.fire() JQ Home  <<  Objects  <<  callbacks.fire()

Invoke the callbacks list.

Description

The callbacks.fire() Callbacks object method, allows us to invoke the callback list with the specified arguments.

Syntax

Signature Description
callbacks.fire(arguments)Invoke the callback list with the specified arguments.

Parameters

Parameter Description Type
argumentsThe argument or list of arguments to pass back to the callback list.Array

Return

undefined.

callbacks.fire( arguments ) Example Objects  <<  Top

Invoke the callback list with the specified arguments.

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(){
  $('#btn1').one('click', function(){
    var ourCallbacks = $.Callbacks();
    ourCallbacks.add( aFunc );
    ourCallbacks.fire( 'The aFunc function was fired from our callbacks. <br />', '#div1');
    ourCallbacks.add( bFunc );
    ourCallbacks.fire( 'The bFunc function was fired from our callbacks. <br />', '#div1');
  });
  function aFunc( value, div ){
    $(div).append( value);
  }
  function bFunc( value, div ){
    aFunc('Passing bFunc function value to aFunc. <br />', div);
  }
});

div1. Some initial text.

Press the button below to action the above code:

Related Tutorials

jQuery Advanced Tutorials - Lesson 6 - The Callbacks Object