MUTATION OBSERVERS
The MutationObserver
API, a relatively recent addition to the DOM specification, allows you to asynchronously execute a callback when the DOM is modified. With a MutationObserver
, you are able to observe an entire document, a DOM subtree, or just a single element. Furthermore, you are also able to observe changes to element attributes, child nodes, text, or any combination of the three.
Basic usage
A MutationObserver
instance is created by calling the MutationObserver
constructor and passing a callback function:
let observer = new MutationObserver(() => console.log('DOM was mutated!'));
The observe() method
This instance begins unassociated with any part of the DOM. To link this observer with the DOM, the observe()
method is used. This method accepts two required arguments: the target DOM node which is observed for changes, and the MutationObserverInit...