Created
March 6, 2014 05:08
-
-
Save NoMan2000/9382975 to your computer and use it in GitHub Desktop.
Mutation Observer Selection
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
| /* 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