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

Callback contained within the callbacks list.

Description

The callbacks.has() Callbacks object method, allows us to determine whether the callback list contains the specified callback.

Syntax

Signature Description
callbacks.has( callback )Determine whether the callback list contains the specified callback.

Parameters

Parameter Description Type
callbackThe callback to look for.Function

Return

A Boolean object.

callbacks.has( callback ) Example Objects  <<  Top

Determine whether the callback list contains the specified callback.

In the example below when we press the button the first time we add the aFunc function and then test to see if the bFunc function has been added to our callbacks list using the callbacks.has() method. This returns false which we output in a message. We then add the bFunc function and then test to see if the function has been added to our callbacks list, again using the callbacks.has() method. This time the method returns true which we output in a message.


$(function(){
  $('#btn10').one('click', function(){
    var ourCallbacks = $.Callbacks();
    ourCallbacks.add( aFunc );
    $('#div10').append( 'Callbacks list contains bFunc? ' + ourCallbacks.has(bFunc) + '<br />');
    ourCallbacks.add( bFunc );
    $('#div10').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);
  }
});

div10. Some initial text.

Press the button below to action the above code:

Related Tutorials

jQuery Advanced Tutorials - Lesson 6 - The Callbacks Object