Favorites

DOM MutationObserver.observe() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
MutationObserver.observe()
DOM MutationObserver MethodThis method is supported by all modern browsers.
Updated 28th November 2026

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, attributeOldValue and characterDataOldValue. At least one of the first three must be true.

Return Value

None (undefined).

Example

<div id="box" class="a">Box</div>
const box = document.getElementById('box');
const mo = new MutationObserver(list => list.forEach(r => console.log(r.attributeName, 'was', r.oldValue)));
mo.observe(box, { attributes: true, attributeFilter: ['class'], attributeOldValue: true });
box.className = 'b';
box.title = 'ignored';
box.className = 'c';

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee