Skip to content

Instantly share code, notes, and snippets.

@markbiek
Created November 1, 2012 16:49
Show Gist options
  • Save markbiek/3994982 to your computer and use it in GitHub Desktop.
Save markbiek/3994982 to your computer and use it in GitHub Desktop.
Stupid simple example of jQuery custom events
/*
Fiddle: http://jsfiddle.net/SBp85/18/
Markup:
<p><a href="#" id="button"><img src="http://placekitten.com/64/64" alt="Click" /></a></p>
<div id="console"></div>
*/
var dbg = function(msg) {
$('#console').append(msg+'<br />');
};
$(document).on( 'buttonClick', function(e, data) {
dbg('buttonClick!');
console.log(e);
console.log(data);
});
$('#button').click( function(e) {
e.preventDefault();
$(document).trigger('buttonClick', [ {data: [1,2,3]} ]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment