Search code examples
webkitchromiummutation-observers

Mutation Observers---subtree


I am reading this http://lists.w3.org/Archives/Public/public-webapps/2011JulSep/1622.html and it seems that Chrome's behavior contrasts to specification. If I understood the specs correctly, defining "subtree" for an element means that changes to the subtree of that element (including the element itself) should be reported. However, when executing this piece of code, I get nothing.

var observer = new WebKitMutationObserver(function(e){console.log(e);})
observer.observe(document.body, {subtree:true, attributes:true});
document.body.appendChild(document.createElement('div'));

What am I missing? Can somebody elaborate on this? Thanks!


Solution

  • The documentation is unclear, but subtree is ignored unless you also specify childList:true.

    The case for attributes and attributeFilter is the same.

    Hope it still helps.