Last active
August 14, 2017 11:41
-
-
Save davidgarsan/4b3b2918637582b115371fb8c341f384 to your computer and use it in GitHub Desktop.
This file contains 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
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