Web APIs

MutationObserver.observe()

Try the free JavaScript compiler

MutationObserver reports matching mutation records asynchronously. observe configures which mutations to watch; disconnect stops observation and discards queued records. Use takeRecords if you need to retrieve pending records directly.

Formal Syntax & Structure

javascript syntaxjavascript
observer.observe(target, options)

Parameters & Attributes

NameTypeDescription
targetNodeNode to observe.
optionsMutationObserverInitMutation types and scope.

Return Value

undefined

No result value.

Working Example

Example Snippetjavascript
const e=document.createElement("div");const o=new MutationObserver(()=>{});o.observe(e,{childList:true});e.append(document.createElement("p"));console.log(o.takeRecords().length);o.disconnect();
JavaScript Reference