const targetNode = document.querySelector("#someElement");
const observerOptions = {
childList: true,
attributes: true,
};
const observer = new MutationObserver(callback);
observer.observe(targetNode, observerOptions);
/* later, when it's time to stop observing… */
/* handle any still-pending mutations */
let mutations = observer.takeRecords();
observer.disconnect();
if (mutations.length > 0) {
callback(mutations);
}MutationObserver: takeRecords() method / notebook
MutationObserver: takeRecords() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.