1.0.0 • Published 8 years ago

delegate-handler v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

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('li', pickFavourite));

support

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

1.0.0

8 years ago