MutationObserver

A browser object that watches part of the DOM and reports changes, such as added nodes or changed attributes, in batches.

In more detail

You call observe(target, options) with options such as childList, attributes, subtree and attributeFilter. Changes are delivered as MutationRecord objects to your callback in a microtask, several at once. Always call disconnect() when you no longer need it, or it keeps the observed nodes alive.

Example

observer.observe(root, { childList: true, attributes: true, attributeFilter: ['data-theme'], subtree: true })

Related terms

Taught in

References