Tip: Click lines to highlight, hold ctrl/cmd to multi-select
JavaScript event delegator template for jQuery (2-Oct @ 13:48)
Syntax Highlighted Code
- jQuery(document).ready(function() {
- jQuery("body").click(function(e) {
- var target = jQuery(e.target);
- if (target.hasClass('someclass')) return doSomeStuff();
- if (target.hasClass('someotherclass')) return doOtherStuff();
- });
- });
Plain Code
jQuery(document).ready(function() {
jQuery("body").click(function(e) {
var target = jQuery(e.target);
if (target.hasClass('someclass')) return doSomeStuff();
if (target.hasClass('someotherclass')) return doOtherStuff();
});
});