Created
November 1, 2012 16:49
-
-
Save markbiek/3994982 to your computer and use it in GitHub Desktop.
Stupid simple example of jQuery custom events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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