Created
April 3, 2018 20:23
-
-
Save masterfermin02/5536b3b5e551840bee446e5cfddffa2f to your computer and use it in GitHub Desktop.
observeDOM
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 observeDOM = (function(){ | |
var MutationObserver = window.MutationObserver || | |
window.WebKitMutationObserver; | |
return function(obj, thistime, callback){ | |
if(typeof obj === 'undefined'){ | |
console.log('obj is undefined'); | |
return; | |
} | |
if( MutationObserver ){ | |
// define a new observer | |
var obs = new MutationObserver(function(mutations, observer){ | |
if( mutations[0].addedNodes.length || mutations[0].removedNodes.length ){ | |
callback('pass other observations back...'); | |
}else if(mutations[0].attributeName == "value" ){ | |
// use callback to pass back value of hidden form field | |
callback( obj.value ); | |
} | |
}); | |
// have the observer observe obj for changes in children | |
// note 'attributes:true' else we can't read the input attribute value | |
obs.observe( obj, { childList:true, subtree:true, attributes:true }); | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment