coderef

MutationObserverBaseline · Widely available

The MutationObserver API watches for changes to the DOM tree and calls a callback function when DOM changes occur.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Jul 29, 2015. Widely available since Jan 29, 2018.

Browser support

DesktopChrome
1–25Not supported
26+Supportedsince Mar 26, 2013
Current: 155
Edge
12+Supportedsince Jul 29, 2015
Current: 154
Firefox
1–13Not supported
14+Supportedsince Jul 17, 2012
Current: 157
Safari
1–6Not supported
7+Supportedsince Oct 22, 2013
Current: 27
MobileChrome Android
18–25Not supported
26+Supportedsince Apr 3, 2013
Current: 155
Firefox Android
4–10Not supported
14+Supportedsince Jun 26, 2012
Current: 157
Safari iOS
1–6Not supported
7+Supportedsince Sep 18, 2013
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

JS
const observer = new MutationObserver((mutations) => {
  for (const m of mutations) console.log(m.type, m.addedNodes);
});

observer.observe(document.body, { childList: true, subtree: true });
// later: observer.disconnect();

Feature detection

JS · check before using
if ("MutationObserver" in globalThis) {
  // MutationObserver is available
} else {
  // load a polyfill or use a fallback
}

Sub-features

Support for each part of the feature (15). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
MutationObserver261214726147
MutationObserver.MutationObserver261214726147
MutationObserver.disconnect261214726147
MutationObserver.observe261214726147
MutationObserver.takeRecords261214726147
MutationRecord161214718147
MutationRecord.addedNodes161214718147
MutationRecord.attributeName161214718147
MutationRecord.attributeNamespace161214718147
MutationRecord.nextSibling161214718147
MutationRecord.oldValue161214718147
MutationRecord.previousSibling161214718147
MutationRecord.removedNodes161214718147
MutationRecord.target161214718147
MutationRecord.type161214718147