DOM MutationObserver.observe() Method
The observe() method starts a MutationObserver watching a node for the kinds of change you choose.
Description
The observe() method tells a MutationObserver which node to watch and for what. childList reports added and removed children, attributes reports attribute changes (optionally limited with attributeFilter), characterData reports text changes, and subtree extends all of these to every descendant. One observer can watch several targets. Use disconnect() to stop and takeRecords() to collect pending changes.
Calling observe() again on the same target with new options replaces the old options for that target. Observers don't stop on their own when the target is removed, so call disconnect() when you no longer need them.
Records are delivered in batches as a microtask, after the current script finishes, so several quick changes arrive together in one callback. That makes observers efficient, but means the DOM may already have changed again by the time your callback runs.
Syntax
observer.observe(target, options)Parameters
- targetThe node to watch.
- optionsWhat to watch:
childList,attributes,characterData,subtree,attributeFilter,attributeOldValueandcharacterDataOldValue. At least one of the first three must betrue.
Return Value
None (undefined).
Example
Browser Support
The following information will show you the current browser support for the MutationObserver.observe() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





