Skip to content

brunoscopelliti/delegate

Repository files navigation

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.

Releases

No releases published

Packages

No packages published