Last active
August 29, 2015 14:14
-
-
Save wmakeev/96ca317e4d7c500969a2 to your computer and use it in GitHub Desktop.
MutationObserver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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