w3resource

jQuery: Check if the callbacks have already been called at least once

jQuery Fundamental - I : Exercise-47

Using jQuery check if the callbacks have already been called at least once.

Sample solution :

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 check if the callbacks have already been called at least once.</title>
  </head>
  <body>
</body>
  </html>

JavaScript Code :

// A sample  function f1
var f1 = function( value ) {
  console.log( "f1:" + value );
};
 
var callbacks = $.Callbacks();
 
// Add the function "f1" to the list
callbacks.add(f1);
 
// Fire the items on the list
callbacks.fire("JavaScript" ); 
callbacks.fire( "jquery" ); 
 
// Test if the callbacks have been called
console.log( callbacks.fired() );

See the Pen jquery-fundamental-exercise-47 by w3resource (@w3resource) on CodePen.


Contribute your code and comments through Disqus.

Previous: Call all of the callbacks with the given arguments.
Next: Fire a list of callbacks with a specific context and an array of arguments.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/jquery-exercises/1/jquery-fundamental-exercise-47.php