Tip: Click lines to highlight, hold ctrl/cmd to multi-select

JavaScript event delegator template for jQuery (2-Oct @ 13:48)

www.flickr.com-photos-bjarlestam

Syntax Highlighted Code

  1. jQuery(document).ready(function() {
  2.     jQuery("body").click(function(e) {
  3.         var target = jQuery(e.target);
  4.  
  5.         if (target.hasClass('someclass')) return doSomeStuff();
  6.         if (target.hasClass('someotherclass')) return doOtherStuff();
  7.     });
  8. });

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();
    });
});

Codedump Run

Permalink: http://codedumper.com/javascript-event-delegator-template-for-jquery