Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created April 9, 2010 20:06
Show Gist options
  • Save cowboy/361531 to your computer and use it in GitHub Desktop.
Save cowboy/361531 to your computer and use it in GitHub Desktop.
Triggering bound event handlers
// The jQuery way.
$(elem).bind( 'foo.bar', function(event){
do_something( event.target );
}).triggerHandler( 'foo.bar' );
// The old-school silly way.
function fn( event ){
do_something( event.target );
};
$(elem).bind( 'foo.bar', fn );
fn( $.Event('click') );
// The new school silly way.
$(elem).bind( 'foo.bar', (function fn(event){
do_something( event.target );
return fn;
})( $.Event('click') ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment