An implementation of delegation, based on jQuery's .on() function.
Check out the demo here: http://jsbin.com/joxeji/edit?html,output
delegate (
node, // The node to delegate the event to.
event, // The event (I.E. "click").
handler, // A function to handle the event.
selector, // CSS selector to match the target child nodes.
[data] // [optional] Data to pass on to the handler function.
)
Created by Alexei Barnes (@Alexei_Barnes) at AlexeiBarnes.com.
See the 140byt.es site for a showcase of entries (built itself using 140-byte entries!), and follow @140bytes on Twitter.
Improved this by using .matches which is now fairly well supported. If your browser is up to date then as of writing only opera mini and IE will not run this code.
Note that even with a polyfill for matches IE will not run this code because for some reason the event target is not an Element.
Info: http://caniuse.com/#search=matches