Lightweight event delegation.
Every commit gets tested across different browsers, and OS.
Here's the latest report
Consider the following DOM tree
<ul id='favourites'>
<li>Apple</li>
<li>Banana</li>
<li>Cherry</li>
<!-- a long list ... -->
</ul>
That's one of the possible way to register an event handler that is executed every time a list entry is clicked
function pickFavourite(event){
// do stuff
}
document.getElementById('favourites')
.addEventListener('click', delegate(pickFavourite, 'li'));
It internally uses Element#matches
. You have to provide a polyfill on very old browsers.