Miss any of our Open RFC calls?Watch the recordings here! »

@wide/dom-observer

2.0.0 • 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

Keywords

none

Install

npm i @wide/dom-observer

DownloadsWeekly Downloads

2

Version

2.0.0

License

MIT

Unpacked Size

9.46 kB

Total Files

5

Last publish

Collaborators

  • avatar
  • avatar
  • avatar
  • avatar