Skip to content

Instantly share code, notes, and snippets.

@kabilashgit
Created March 20, 2019 12:26
Show Gist options
  • Save kabilashgit/738a4980b337c1a450bb5e4d33b8e050 to your computer and use it in GitHub Desktop.
Save kabilashgit/738a4980b337c1a450bb5e4d33b8e050 to your computer and use it in GitHub Desktop.
Listen DOM changed using MutationObserver

/* Author : Manikandan K */

Listen DOM changed using MutationObserver

MutationObserver = window.MutationObserver || window.WebKitMutationObserver;

var observer = new MutationObserver(function(mutations, observer) {
    // fired when a mutation occurs
    // console.log(mutations, observer);
    
    markHighlight(); // write your condition here
});

/*
 * define what element should be observed by the observer
 * and what types of mutations trigger the callback
 */ 
observer.observe(document, {
    subtree: true,
    attributes: true    
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment