Favorites

DOM MutationObserver Interface

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

MutationObserver
DOM InterfaceThis interface is supported by all modern browsers.
Updated 28th November 2026

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

NameDescription
MutationObserver.observe()The observe() method starts a MutationObserver watching a node for the kinds of change you choose.

Example

<ul id="list"></ul>
const list = document.getElementById('list');
const observer = new MutationObserver(records => {
  for (const r of records) {
    console.log(r.type, 'added:', r.addedNodes.length, 'attr:', r.attributeName);
  }
});
observer.observe(list, { childList: true, attributes: true });
list.append(document.createElement('li'));
list.setAttribute('data-count', '1');

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.

This interface 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

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.