@wide/dom-observer

2.1.1 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @wide/dom-observer

Weekly Downloads

138

Version

2.1.1

License

MIT

Unpacked Size

9.66 kB

Total Files

5

Last publish

Collaborators

  • gflandin
  • myeti
  • jmartinsdacosta
  • robiseb