callbacks.remove()S2C Home « Objects « callbacks.remove()

Callback list function removal.

Description

The callbacks.remove() Callbacks object method, allows us to remove callback(s) from a callback list.

Syntax

Signature Description
callbacks.remove( callback )Remove callback(s) from a callback list.

Parameters

Parameter Description Type
callbackA function, or array of functions, to be removed from the callback list. Function or
Array

Return

undefined

callbacks.remove( callback ) ExampleTop

Remove callback(s) from a callback list.

In the example below when we press the button the first time we add the aFunc function and fire this off. We then add and remove the bFunc function from our callbacks list. We then use the callbacks.has() method to see if the aFunc and bFunc functions exist in the callback list and output a message for each function.


$(function(){
  $('#btn13').one('click', function(){
    var ourCallbacks = $.Callbacks();
    ourCallbacks.add( aFunc );
    ourCallbacks.fire( 'The aFunc function was fired from our callbacks. <br>', '#div13');
    ourCallbacks.add( bFunc );
    ourCallbacks.remove( bFunc );
    $('#div13').append( 'Callbacks list contains aFunc? ' + ourCallbacks.has(aFunc) + '<br>');
    $('#div13').append( 'Callbacks list contains bFunc? ' + ourCallbacks.has(bFunc) + '<br>');
  });
  function aFunc( value, div ){
    $(div).append( value);
  }
  function bFunc( value, div ){
    aFunc('Passing bFunc function value to aFunc. <br>', div);
  }
});

div13. Some initial text.

Press the button below to action the above code: