Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hughsk/watch-child-nodes
Watch the child list of a DOM node, calling a function for each new element and each element removed.
https://github.com/hughsk/watch-child-nodes
Last synced: 8 days ago
JSON representation
Watch the child list of a DOM node, calling a function for each new element and each element removed.
- Host: GitHub
- URL: https://github.com/hughsk/watch-child-nodes
- Owner: hughsk
- License: mit
- Created: 2015-09-14T06:10:07.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-09-14T06:10:15.000Z (about 9 years ago)
- Last Synced: 2024-10-17T16:41:14.699Z (22 days ago)
- Language: JavaScript
- Homepage:
- Size: 105 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# watch-child-nodes
[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)
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](https://nodei.co/npm/watch-child-nodes.png)](https://www.npmjs.com/package/watch-child-nodes)
### `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*.
``` javascript
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`.
``` javascript
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](http://github.com/hughsk/watch-child-nodes/blob/master/LICENSE.md) for details.