DOM MutationObserver Interface
MutationObserver watches part of the page for changes, such as added or removed elements, changed attributes or text, and calls a function when they happen.
Description
A MutationObserver lets you watch for changes to the DOM. Create one with a callback, then call observe(target, options), choosing what to watch: childList (added and removed children), attributes, characterData (text) and subtree (all descendants). The callback receives a list of MutationRecord objects describing what changed.
Callbacks run in batches after the changes, not during them, which keeps it efficient. Call disconnect() when you no longer need it. It's useful for reacting to content added by third-party scripts or frameworks.
Each MutationRecord includes the type of change, the target node, addedNodes and removedNodes for child changes, the attributeName, and optionally the oldValue. Watching an entire document with subtree: true can produce many records, so keep the callback quick and watch the smallest part of the page you can.
Methods
| Name | Description |
|---|---|
MutationObserver.observe() | The observe() method starts a MutationObserver watching a node for the kinds of change you choose. |
Example
Browser Support
The following information will show you the current browser support for the MutationObserver interface. Hover over a browser icon to see the version that first introduced support for this interface.
Desktop





Tablets & Mobile





