Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

delegate-events

HenrikJoreteg22.7k1.1.1

Event delegation component

delegate, delegation, event, events

readme

delegate

Low-level event delegation component. Forked from component/delegate for use with browserify.

Installation

$ npm install delegate-events

Example

var delegate = require('delegate-events');
var ul = document.querySelector('ul');
var n = 0;

var fn = delegate.bind(ul, 'li a', 'click', function(e){
  console.log(e.target);
  console.log(e.delegateTarget); // => "<a>"
  if (++n == 3) {
    console.log('unbind');
    delegate.unbind(ul, 'click', fn, false);
  }
}, false);

API

.bind(el, selector, type, callback, [capture])

Bind and return a callback which may be passed to .unbind().

.unbind(el, type, callback, [capture])

Unbind.

Tests

  • Run npm test.
  • Open test/index.html in a browser.
  • Open the js console and verify that interacting with the elements works as they say they should.

License

MIT

changelog

0.2.1 / 2013-10-02

  • optimize closest

0.2.0 / 2013-09-30

  • delegate child elements, closes #3
  • Fixed e.target for IE [anthonyshort]
  • Use call() to correctly assign this in handler [necolas]
  • remove weird dead code. Closes #4

0.1.0 / 2012-12-19

  • add "event" dependency for x-browser