jQuery: Remove all of the callbacks from a list
jQuery Fundamental - I : Exercise-45
Using jQuery remove all of the callbacks from a list.
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 remove all of the callbacks from a list.</title>
</head>
<body>
</body>
</html>
JavaScript Code :
// Sample function (f1) to be added to a callbacks list
var f1 = function( value1, value2 ) {
console.log( "f1: " + value1 + "," + value2 );
};
// Another function (f2) to also be added to the list
var f2 = function( value1, value2 ) {
console.log( "f2: " + value1 + "," + value2 );
};
var callbacks = $.Callbacks();
// Add the two functions
callbacks.add( f1 );
callbacks.add( f2 );
// Empty all callbacks
callbacks.empty();
// Test to confirm all callbacks have been removed
console.log( callbacks.has( f1 ) );
console.log( callbacks.has( f2 ) );
See the Pen jquery-fundamental-exercise-45 by w3resource (@w3resource) on CodePen.
Contribute your code and comments through Disqus.
Previous: Test if the callback list has been disabled.
Next: Call all of the callbacks with the given arguments.
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-45.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics