Home  >  jQuery

Example of callbacks.remove() in jQuery

March 30, 2013
remove() in jQuery removes the callback function from the callback list. Once removed then no fire() will execute the callback method. Find the syntax below.
callbacks.remove()
 
Find sample example below.

<html>
<body>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
var show = function( val ) {
	console.log(val);
};

var callbacks = $.Callbacks();

callbacks.add( show );

callbacks.fire("Hellow");

callbacks.remove(show);

callbacks.fire("World!");

</script>
</body>
</html>

Output
Hellow
 
In the example, we have added show function in callback list. We use the fire() with value “Hellow” and it printed in console. Then we removed the show function and then again called fire() with value “World!” and now it will not print.
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us