1.0.0 • Published 9 years ago

watch-child-nodes v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

watch-child-nodes

stable

Watch the child list of a DOM node, calling a function for each new element and each element removed.

Useful for adding implicit characteristics to the children of a DOM node, without having to worry about any new elements being added/removed as time goes on.

Usage

NPM

dispose = watch(element, enter, exit)

Watches a DOM element's child list for additions and removals.

enter is called once for each existing child node and once for each new node.

exit is called once for each node removed.

const watch = require('watch-child-nodes')

watch(parent, function enter (node) {
  console.log('new node!', node)
}, function exit (node) {
  console.log('old node!', node)
})

The dispose function returned from watch can be used to disable the watcher, preventing any future calls of enter or exit.

const watch = require('watch-child-nodes')

const dispose = watch(parent, enter, exit)

// stop watching for changes after the
// first second:
setTimeout(function () {
  dispose()
}, 1000)

License

MIT, see LICENSE.md for details.