Skip to content

Instantly share code, notes, and snippets.

@davidgarsan
Last active August 14, 2017 11:41
Show Gist options
  • Save davidgarsan/4b3b2918637582b115371fb8c341f384 to your computer and use it in GitHub Desktop.
Save davidgarsan/4b3b2918637582b115371fb8c341f384 to your computer and use it in GitHub Desktop.
function attributeChangeDetector(element, callback) {
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type == 'attributes') {
console.log('Attribute ' + mutation.attributeName + ' changed');
!!callback && callback(mutation);
}
});
});
observer.observe(element, {
attributes: true
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment