Menu

gitpiper

observeMutations javascript Code Snippet in 2024

browsereventadvanced

Last Updated: 13 July 2024

Creates a new MutationObserver and runs the provided callback for each mutation on the specified element.

  • Use a MutationObserver to observe mutations on the given element.
  • Use Array.prototype.forEach() to run the callback for each mutation that is observed.
  • Omit the third argument, options, to use the default options (all true).
const observeMutations = (element, callback, options) => { const observer = new MutationObserver(mutations => mutations.forEach(m => callback(m)) ); observer.observe( element, Object.assign( { childList: true, attributes: true, attributeOldValue: true, characterData: true, characterDataOldValue: true, subtree: true, }, options ) ); return observer; };
const obs = observeMutations(document, console.log); // Logs all mutations that happen on the page obs.disconnect(); // Disconnects the observer and stops logging mutations on the page

javascript snippet similar to observeMutations For You in July 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️