jQuery: Disable a callback list from doing anything more
jQuery Fundamental - I : Exercise-43
Disable a callback list from doing anything more.
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>Disable a callback list from doing anything more.</title>
</head>
<body>
</body>
</html>
JavaScript Code :
var f1 = function( value ) {
console.log( value );
};
var callbacks = $.Callbacks();
// Add the above function to the list
callbacks.add( f1 );
// Fire the items on the list
callbacks.fire( "jQuery" );
// Disable further calls being possible
callbacks.disable();
// Attempt to fire with "JavaScript" as an argument
callbacks.fire( "JavaScript" );
// JavaScript isn't output
See the Pen jquery-fundamental-exercise-43 by w3resource (@w3resource) on CodePen.
Contribute your code and comments through Disqus.
Previous: Using jQuery add a callback or a collection of callbacks to a callback list.
Next: Test if the callback list has been disabled.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
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-43.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics