Skip to content

Instantly share code, notes, and snippets.

@NoMan2000
Created March 6, 2014 05:08
Show Gist options
  • Select an option

  • Save NoMan2000/9382975 to your computer and use it in GitHub Desktop.

Select an option

Save NoMan2000/9382975 to your computer and use it in GitHub Desktop.
Mutation Observer Selection
/* The following are mutation observers for performance reasons. */
var canObserveMutation = 'MutationObserver' in window;
if(canObserveMutation){
var observer, callback;
callback = function( allmutations ){
allmutations.map( function(mr){
console.dir(mr);
var mt = 'Mutation type: ' + mr.type; // log the type of mutation
mt += 'Mutation target: ' + mr.target; // log the node affected.
console.log( mt );
});
};
observer = new MutationObserver( callback );
var options = {
'childList': true,
'attributes':true,
'characterData':true,
'subtree':true,
'attributeOldValue':true,
'characterDataOldValue':true,
'attributeFilter':true
};
var docBody = document.querySelector( 'body' );
observer.observe( docBody, options );
/* observer.disconnect to remove the connection. */
}/* End canObserveMutation */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment