This repository includes a collection of MutationObserver polyfills so that you can use MutationObserver in all browsers (>= IE8). The browser breakdown is:
- IE8: jQuery polyfill
- IE9 and IE10: Mutation Events polyfill
- IE11, Chrome, Safari, Firefox, Opera: Native MutationObserver
This polyfill is available from Bower:
bower install mutationobserver
This polyfill uses Steal so the best way to use it is to steal the main mutationobserver.js
file which will return a MutationObserver constructor that you can use:
steal("mutationobserver", function(Observer) {
var observer = new Observer(function(mutations) {
console.log(mutations);
});
observer.observe($("body")[0], {
attributes: true,
childList: true
});
});
Feature | Native | Events Polyfill | jQuery Polyfill |
---|---|---|---|
childList | ✓ | ✓ | ✓ |
attributes | ✓ | ✓ | ✓ |
characterData | ✓ | ✓ | ✗ |
subtree | ✓ | ✓ | ✓ |
attributeOldValue | ✓ | ✓ | ✓ |
characterDataOldValue | ✓ | ✓ | ✗ |
attributeFilter | ✓ | ✓ | ✓ |
jQuery has no way to manipulate a CharacterData's data property, so there is no practical way to do this. Most commonly people manipulate text content using text()
which would result in new TextNodes anyways.
To contribute first clone the repository then run bower install
which will install the development dependencies (just QUnit). Then navigate to test/test.html
to see the tests. If you find a bug create a test in one of the appropriate files:
attributes_test.js
is for the "attributes" event.childlist_test.js
is for the "childList" event.mutationobserver_test.js
is for generic tests that make sure the API is fully supported.
The Mutation Events polyfill is taken from the Polymer Project and has a BSD license.
Otherwise this project is MIT licensed.