0

I'm trying to listen for changes in a XML structure using Javascript. I've got the 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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
lucas clemente
  • 6,255
  • 8
  • 41
  • 61

2 Answers2

2

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.

Tim Down
  • 318,141
  • 75
  • 454
  • 536
1

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

This really is a bug in Webkit.

lucas clemente
  • 6,255
  • 8
  • 41
  • 61