-
-
Save brandonaaron/323038 to your computer and use it in GitHub Desktop.
This file contains 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
// 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 file contains 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
//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