Skip to content

Instantly share code, notes, and snippets.

@wmakeev
Last active August 29, 2015 14:14
Show Gist options
  • Save wmakeev/96ca317e4d7c500969a2 to your computer and use it in GitHub Desktop.
Save wmakeev/96ca317e4d7c500969a2 to your computer and use it in GitHub Desktop.
MutationObserver
// https://developer.mozilla.org/en/docs/Web/API/MutationObserver
// create an observer instance
var observer = new MutationObserver(function(mutations) {
console.log(mutations);
});
// configuration of the observer:
var config = {
attributes: true,
childList: true,
characterData: true,
//subtree: true,
attributeOldValue: true,
characterDataOldValue: true,
//attributeFilter: []
};
// select the target node
var target = document.querySelector('.pump-title-panel');
// pass in the target node, as well as the observer options
observer.observe(target, config);
// later, you can stop observing
observer.disconnect();
var handleChanges = function (changes) {
console.log(changes);
};
var observer = new MutationSummary({
callback: handleChanges, // required
//rootNode: myDiv, // optional, defaults to window.document
observeOwnChanges: true, // optional, defaults to false
oldPreviousSibling: true, // optional, defaults to false
queries: [
{ all: true },
// { /* query2 */ },
]
});
// If/when change report callbacks are no longer desired
// var summaries = observer.disconnect();
// if (summaries) handleChangesUpToHere(summaries);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment