Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 288
bellpeace Avatar asked May 12 '12 01:05

bellpeace


1 Answers

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.

like image 70
karnyj Avatar answered Oct 01 '22 02:10

karnyj