@wide/dom-observer
v2.1.1
Published
Fast and reliable DOM observer
Keywords
Readme
DOM Observer
Fast and reliable DOM observer.
Install
npm install @wide/dom-observer --saveUsage
Observe selector
observe(selector, { bind[, unbind] })selectorquery selector to observebind(el)hook called when an element matching the selector appears in the DOMunbind(el)hook called when this same element is removed from the DOM (optional)
Exemple:
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:
import { unobserve } from '@wide/dom-observer'
unobserve('[data-foobar]')Unbind element
Unbind all selectors for a specific element.
unbind(el)Exemple:
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:
import { seek } from '@wide/dom-observer'
seek('[data-foobar]') // Array<HTMLElement>Authors
- Aymeric Assier - github.com/myeti
- Julien Martins Da Costa - github.com/jdacosta
License
This project is licensed under the MIT License - see the licence file for details
