wide / dom-observer

Fast and reliable DOM observer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:

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

License

This project is licensed under the MIT License - see the licence file for details

About

Fast and reliable DOM observer.

License:MIT License


Languages

Language:JavaScript 100.0%