https://github.com/steelydylan/event-on-off
simple event delegation system
https://github.com/steelydylan/event-on-off
Last synced: about 1 year ago
JSON representation
simple event delegation system
- Host: GitHub
- URL: https://github.com/steelydylan/event-on-off
- Owner: steelydylan
- License: mit
- Created: 2017-06-06T17:18:37.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-08T16:40:43.000Z (about 9 years ago)
- Last Synced: 2025-05-10T01:45:05.004Z (about 1 year ago)
- Language: JavaScript
- Size: 64.5 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# event-on-off
A low-level module which supports jquery-like event delegations.
If you have ever used jQuery 'on' method, then you already know how to use this.
## Install
npm
```
npm install event-on-off --save
```
or yarn
```
yarn add event-on-off
```
## Usage
```js
import { on, off } from 'event-on-off';
const parent1 = document.querySelector("#test");
on(parent1, ".btn", "click", () => {
document.querySelector("#test-result").innerText = 'ok';
});
```
```html
test
```
## Also
you can listen more than 2 events at once
```js
const parent2 = document.querySelector("#test2");
on(parent2, ".btn", "mousedown mouseup", (e) => {
if (e.type === 'mousedown') {
document.querySelector("#test2-result").innerText = 'mousedown';
} else if (e.type === 'mouseup') {
document.querySelector("#test2-result").innerText = 'mouseup';
}
});
```