Home  >  jQuery

Example of callbacks.add() in jQuery

March 29, 2013
add() in callback list, adds a function or collection of function. We need to create callback list as
var callbacks = $.Callbacks(); 
 
And then add the function as below.
callbacks.add( show );
 
Find the 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( "hello" );

callbacks.fire( "World!" );

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

Output in console will look like
Hello
World!
 
FIND MORE TUTORILAS






©2019 concretepage.com | Privacy Policy | Contact Us