Package detail

on-load

shama7.5kMIT5.0.0

On load/unload events for DOM elements using a MutationObserver

html, dom, element, onload

readme

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

changelog

on-load Change Log

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

5.0.0 - 2023-04-02

  • Call latest on/off callbacks and now using let/const internally instead of var - (#16)
  • Code optimization - (#41)

4.0.2 - 2019-03-29

  • Fix timing/loading collision bug - (#40)

4.0.1 - 2018-08-10

  • Allow observation before the document is ready - (#39)

4.0.0 - 2018-08-10

  • Only load/unload nodes if document.documentElement.contains(node) - (#35)
  • Switch from testron to tape-run.

3.4.1 - 2018-06-28

  • Tweak browser export definition format

3.4.0 - 2018-02-18

  • Observer attached further up the DOM to document.documentElement instead of body

3.3.4 - 2017-12-03

  • Fix node export

3.3.3 - 2017-12-03

  • Noop version to skip over unpublished 3.3.2

3.3.2 - 2017-12-03

  • Fix export for unbundled electron imports.
  • Update deps