开发者

Mutation events in Javascript not working

开发者 https://www.devze.com 2023-02-02 18:18 出处:网络
I\'m trying to listen for changes in a XML structure using Javascript. I\'ve got the开发者_如何学JAVA following code:

I'm trying to listen for changes in a XML structure using Javascript. I've got the开发者_如何学JAVA following code:

var doc = document.implementation.createDocument("", "root", null);
doc.addEventListener("DOMNodeInserted", function(event) {
                       alert("changed!");
                     }, false);
doc.documentElement.appendChild(doc.createElement("test"));

This is not working. However the following code does work:

document.addEventListener("DOMNodeInserted", function(event) {
                           alert("changed!");
                          }, false);
document.body.appendChild(doc.createElement("button"));

What am I missing here?


Both your examples work in recent Firefox and Opera but only the second works in WebKit-based browsers (Chrome and Safari). This looks like an oversight or bug in WebKit, although I can't find an issue in their issue tracker about it.


Okay, just found this: https://bugs.webkit.org/show_bug.cgi?id=26147

This really is a bug in Webkit.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号