https://github.com/component/delegate
Event delegation component
https://github.com/component/delegate
Last synced: 12 months ago
JSON representation
Event delegation component
- Host: GitHub
- URL: https://github.com/component/delegate
- Owner: component
- Created: 2012-10-06T22:53:00.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2016-12-22T13:28:16.000Z (over 9 years ago)
- Last Synced: 2025-03-09T19:16:00.997Z (about 1 year ago)
- Language: HTML
- Size: 24.4 KB
- Stars: 35
- Watchers: 7
- Forks: 20
- Open Issues: 6
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
# delegate
Low-level event delegation component.
## Installation
$ component install component/delegate
## Example
```js
var delegate = require('delegate');
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); // => ""
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.
## License
MIT