Skip to content
jshacks.dev
Debugging

Break on DOM changes in DevTools

Find the code that changes an element with a DOM breakpoint in Chrome DevTools for subtree, attribute or removal changes, or log changes with MutationObserver.

1 min read
Summarize in AI

Something keeps changing a button's text or removing a node, and you do not know which script does it. A DOM breakpoint pauses at the exact line that makes the change.

In the Elements panel, right-click the element, then choose Break on and pick one of three:

  • Subtree modifications, when a child is added, removed or moved.

  • Attribute modifications, when an attribute or class changes.

  • Node removal, when the element is removed from the page.

When it triggers, the Sources panel pauses on the script line and the call stack shows who made the change. See the DevTools DOM breakpoints guide.

To record changes without stopping, use a MutationObserver from the console:

JavaScript
const target = document.querySelector("#cart");
new MutationObserver((records) => {
  for (const r of records) console.log(r.type, r.target.id);
}).observe(target, { childList: true, attributes: true });
Text
childList cart
attributes cart

The observer tells you what changed, but not who changed it. Use the breakpoint for the caller, and the observer for a log of the whole session.

Also inBrowser
Share

More snippets

Debugging

Group related logs with console.group

Indent related console output under a label with console.group and console.groupEnd, so interleaved logs from one request stay readable in Node.js 24.

1 min read
APIs

Fetch JSON and handle HTTP errors

Fetch JSON in the browser or Node.js 24 and throw on 404 or 500 yourself, because fetch only rejects on network failure and does not check the status.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.