Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/allouis/deligate
🌟 Event delegation made easy 🌟
https://github.com/allouis/deligate
Last synced: 24 days ago
JSON representation
🌟 Event delegation made easy 🌟
- Host: GitHub
- URL: https://github.com/allouis/deligate
- Owner: allouis
- Created: 2015-10-07T09:56:08.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-10-10T13:42:19.000Z (about 9 years ago)
- Last Synced: 2024-04-25T14:21:09.114Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 145 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Deligate
Simple event delegation
Currently only supports browsers with the [`Element.prototype.matches` method](http://caniuse.com/#feat=matchesselector)
```
npm install deligate
```## Usage
```javascript
var deligate = require('deligate');
document.body.addEventListener('click', deligate('button.some-class', function(event){
console.log('clicked the button');
}));// ... more likely
var handler = deligate('button.some-class', function(event){
console.log('clicked the button');
});document.body.addEventListener('click', handler);
// ... later
document.body.removeEventListener('click', handler);
```## API
#### `var handler = deligate(selector, fn)`
Creates a function that is only called when the selector matches `event.target` passed to it.