Last active
July 16, 2016 22:01
-
-
Save m3g4p0p/01c6b6b7f2bb5c85c4d25cadc3ca15e8 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
$.fn.observe = function(callback, options) { | |
options = options || { | |
attributes: true, | |
childList: true, | |
characterData: true | |
}; | |
$(this).each(function() { | |
var observer = new MutationObserver(callback.bind(this)); | |
observer.observe(this, options); | |
}); | |
return this; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jQuery observe
A jQuery extension to quickly apply a mutation observer to jQuery objects. The first argument is a callback function, within which
this
refers to the current element; also gets the MutationRecord passed as well as the MutationObserver (just as you'd expect). The second argument optionally takes an options object with the usual MutationObserverInit API.Sample usage: