Skip to content

Instantly share code, notes, and snippets.

@ultim8k
Last active February 7, 2019 08:27
Show Gist options
  • Save ultim8k/8766016 to your computer and use it in GitHub Desktop.
Save ultim8k/8766016 to your computer and use it in GitHub Desktop.
Adding a callback handler to a jQuery plugin

Adding a callback handler to a jQuery plugin

(function($){
	$.fn.myAwesomePlugin = function(settings) {
		var callback = settings.callback;
		if ($.isFunction(callback)) {
			var parameter = 'Hello World';
			callback.call(this, parameter);
		}
	};
})(jQuery);

And then when you call your plugin, it would be looking like this:

$("#a-random-element").myAwesomePlugin({
	callback: function(data){
		alert(data);
	}
});

Source: coderwall.com: Eric Martins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment