Skip to content

Latest commit

 

History

History
36 lines (25 loc) · 922 Bytes

README.md

File metadata and controls

36 lines (25 loc) · 922 Bytes

delegate

Lightweight event delegation.

CI reports

Every commit gets tested across different browsers, and OS.

Here's the latest report

how to use

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'));

support

It internally uses Element#matches. You have to provide a polyfill on very old browsers.