7
rated 0 times
[
8]
[
1]
/ answers: 1 / hits: 32392
/ 9 Years ago, fri, june 19, 2015, 12:00:00
Consider the following code:
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
console.log(mutation.target.nodeName);
});
});
observer.observe(document, {
attributes: true,
childList: true,
characterData: true
});
<div>
<ol contenteditable oninput=>
<li>Press enter</li>
</ol>
</div>
which is a slight modification of this.
Interacting with the jsbin version page does not produce any log. Where am I wrong? Notice that if I substitute line
observer.observe(document, {
with
observer.observe(document.querySelector('ol'), {
the script turns on working...
More From » mutation-observers