https://github.com/wide/dom-observer
Fast and reliable DOM observer.
https://github.com/wide/dom-observer
modulus
Last synced: 2 months ago
JSON representation
Fast and reliable DOM observer.
- Host: GitHub
- URL: https://github.com/wide/dom-observer
- Owner: wide
- License: mit
- Created: 2020-05-29T14:58:08.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2021-06-16T21:08:43.000Z (almost 5 years ago)
- Last Synced: 2025-10-02T17:53:59.543Z (6 months ago)
- Topics: modulus
- Language: JavaScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 7
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# DOM Observer
Fast and reliable DOM observer.
## Install
```
npm install @wide/dom-observer --save
```
## Usage
### Observe selector
```
observe(selector, { bind[, unbind] })
```
- `selector` query selector to observe
- `bind(el)` hook called when an element matching the selector appears in the DOM
- `unbind(el)` hook called when this same element is removed from the DOM (optional)
Exemple:
```js
import observe from '@wide/dom-observer'
observe('[data-foobar]', {
bind: el => console.log(`I'm in the DOM !`),
unbind: el => console.log(`I'm no longer in the DOM...`)
})
```
### Unobserve selector
Delete observer for a specific selector, all related elements will be unbinded
```
unobserve(selector)
```
Exemple:
```js
import { unobserve } from '@wide/dom-observer'
unobserve('[data-foobar]')
```
## Unbind element
Unbind all selectors for a specific element.
```
unbind(el)
```
Exemple:
```js
import { unbind } from '@wide/dom-observer'
unbind(document.querySelector('#id'))
```
## Get selector's binded elements
Retrieve the list of binded elements by selector.
```
seek(selector)
```
Exemple:
```js
import { seek } from '@wide/dom-observer'
seek('[data-foobar]') // Array
```
## Authors
- **Aymeric Assier** - [github.com/myeti](https://github.com/myeti)
- **Julien Martins Da Costa** - [github.com/jdacosta](https://github.com/jdacosta)
## License
This project is licensed under the MIT License - see the [licence](licence) file for details