jQuery: Test if the callback list has been disabled
jQuery Fundamental - I : Exercise-44
Test if the callback list has been disabled.
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>Test if the callback list has been disabled.</title>
</head>
<body>
</body>
</html>
JavaScript Code :
// A sample logging function
var f1 = function( value ) {
console.log( "f1:" + value );
};
var callbacks = $.Callbacks();
// Add the function f1 to the callback list
callbacks.add( f1 );
// Fire the items on the list, passing an argument
callbacks.fire( "jQuery" );
// Outputs "f1: jQuery"
// Disable the callbacks list
callbacks.disable();
// Check the disabled state of the list
console.log ( callbacks.disabled() );
// Outputs: true
See the Pen jquery-fundamental-exercise-44 by w3resource (@w3resource) on CodePen.
Contribute your code and comments through Disqus.
Previous: Disable a callback list from doing anything more.
Next: Using jQuery remove all of the callbacks from a list.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework