Update off.md
This commit is contained in:
@ -2,15 +2,15 @@
|
|||||||
|
|
||||||
Removes an event listener from an element.
|
Removes an event listener from an element.
|
||||||
|
|
||||||
Use `EventTarget.removeEventListener()` to remove an event listener from an element. Omit the fourth argument `opts` to use `false` or specify it based on the options used when the event listener was added.
|
Use `EventTarget.removeEventListener()` to remove an event listener from an element.
|
||||||
|
Omit the fourth argument `opts` to use `false` or specify it based on the options used when the event listener was added.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const off = (el, evt, fn, opts = false) => el.removeEventListener(evt, fn, opts);
|
const off = (el, evt, fn, opts = false) => el.removeEventListener(evt, fn, opts);
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// See the `on` snippet.
|
|
||||||
const fn = () => console.log('!');
|
const fn = () => console.log('!');
|
||||||
const ref = on(document.body, 'click', fn, { target: 'p' });
|
document.body.addEventListener('click', fn);
|
||||||
off(document.body, 'click', ref); // no longer logs '!' upon clicking a `p` el child of the body
|
off(document.body, 'click', fn); // no longer logs '!' upon clicking on the page
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user