Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brandonaaron/323038 to your computer and use it in GitHub Desktop.
Save brandonaaron/323038 to your computer and use it in GitHub Desktop.
// Blog post: http://brandonaaron.net/blog/2010/03/4/event-delegation-with-jquery
// Try this instead of the above (didn't test)
$('#container').delegate('a.top', 'click', function(e) {
log( $(this).text() + ' clicked1');
return false;
});
//this one works
$('#container a').filter('.top').bind('click', function(e){
log( $(this).text() + ' clicked1');
return false;
});
//this one does not work
$('#container a').filter('.top').live('click', function(e){
log( $(this).text() + ' clicked1');
return false;
});
//this one does not work. this would have been awesome. it is a direct replacement of bind
$('#container a').filter('.top').delegate('click', function(e){
log( $(this).text() + ' clicked1');
return false;
});
//even this one does not work
$('#container a').delegate('.top', 'click', function(e){
log( $(this).text() + ' clicked1');
return false;
});
//this one works but see how far it is from the original bind statement.
//this break chainability
$('#container a').delegate('.top', 'click', function(e){
log( $(this).text() + ' clicked1');
return false;
});
//tested with jQuery 1.4.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment