Skip to content
/ on-load Public

On load/unload events for DOM elements using a MutationObserver

Notifications You must be signed in to change notification settings

shama/on-load

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

on-load

NPM version build status Downloads js-standard-style

On load/unload events for DOM elements using a MutationObserver

usage

const onload = require('on-load')

const div = document.createElement('div')
onload(div, function (el) {
  console.log('in the dom')
}, function (el) {
  console.log('out of the dom')
})

// Will fire the onload
document.body.appendChild(div)

// ... some time later

// Will fire the onunload
document.body.removeChild(div)

API

onload(node, onloadFn, onunloadFn, [caller])

Pass a dom node to onload to have a onloadFn function fire when the dom node is added to the document dom and a onunloadFn fire when the dom node is removed from the document dom. Optionally a caller ID can be set to associate the onload/onunload hooks with a particular instance of of a dom node. This is commonly used when 'componentizing' dom nodes.

license

(c) 2023 Kyle Robinson Young. MIT License

About

On load/unload events for DOM elements using a MutationObserver

Resources

Stars

Watchers

Forks

Packages

No packages published