An open API service indexing awesome lists of open source software.

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

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';
}
});
```