Q:

Using jQuery add a callback or a collection of callbacks to a callback list

0

Using jQuery add a callback or a collection of callbacks to a callback list.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

HTML Code :

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-git.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Using jQuery add new callbacks to a callback list.</title>
</head>
<body>
</body>
</html>

JavaScript Code :

var f1 = function( value ) {
  console.log( "f1: " + value );
};

var f2 = function( value ) {
  console.log( "f2: " + value );
};
 
var callbacks = $.Callbacks();
 
// Add the function "f1" to the list
callbacks.add(f1);
 
// Fire the above items
callbacks.fire( "jQuery" );

 
// Add the function f2 to the list
callbacks.add(f2 );
 
// Fire the above items  again
callbacks.fire( "Javascript" );
 
// Outputs:
// "foo: world"
// "bar: world"

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now