dom-mutation-notifier
v0.1.0
Published
Friendly interface for MutationObserver.
Downloads
4
Readme
dom-mutation-notifier
Friendly interface for MutationObserver.
Eight events are implemented: (element|attribute|text|comment)(Added|Removed)
The constructor takes the same arguments as the observe
method of MutationObserver
.
If no options are provided, childList
will be watched by default.
MutationNotifier will only start observing when a valid event listener is added (with on
). It will stop observing if all listeners have been removed (with off
).
Usage
var MutationNotifier = require("dom-mutation-notifier")
var notifier = new MutationNotifier(document.querySelector("body"))
var addListener = function(element) {}
var rmListener = function(element) {}
notifier.on("elementAdded", addListener)
// Observing starts
notifier.on("elementRemoved", rmListener)
notifier.off("elementAdded", addListener)
notifier.off("elementRemoved", rmListener)
// Observing ends
License
dom-mutation-notifier is released under the MIT License. Copyright (c) 2017 Braveg1rl