admin管理员组文章数量:1424985
I made this fiddle that listens for a few different MutationEvents
, specifically DOMCharacterDataModified
, DOMSubtreeModified
, and DOMNodeInserted
when changing the innerHTML
of a div.
/
Interestingly, Chrome shows:
DOMCharacterDataModified
, DOMSubtreeModified
while Firefox 5 shows: DOMNodeInserted
.
I'm not actually sure who's correct. I found this old Mozilla bug: .cgi?id=368133 and the W3 docs (.html), but I don't find either particularly enlightening.
Does anyone know what the proper behavior is? I'd love to file a bug on someone so it's consistent.
I made this fiddle that listens for a few different MutationEvents
, specifically DOMCharacterDataModified
, DOMSubtreeModified
, and DOMNodeInserted
when changing the innerHTML
of a div.
http://jsfiddle/newtang/kysTm/15/
Interestingly, Chrome shows:
DOMCharacterDataModified
, DOMSubtreeModified
while Firefox 5 shows: DOMNodeInserted
.
I'm not actually sure who's correct. I found this old Mozilla bug: https://bugzilla.mozilla/show_bug.cgi?id=368133 and the W3 docs (http://www.w3/TR/DOM-Level-2-Events/events.html), but I don't find either particularly enlightening.
Does anyone know what the proper behavior is? I'd love to file a bug on someone so it's consistent.
Share Improve this question edited Mar 27, 2022 at 22:34 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jun 29, 2011 at 23:43 NewtangNewtang 6,55411 gold badges53 silver badges72 bronze badges 2- I filed this Chromium bug based on the answers: code.google./p/chromium/issues/detail?id=88195 – Newtang Commented Jul 1, 2011 at 17:20
- Opened a Webkit bug: bugs.webkit/show_bug.cgi?id=93787 – Newtang Commented Aug 12, 2012 at 21:05
2 Answers
Reset to default 3WebKit has an "optimization" where if you set innerHTML to something that contains no markup and the first child of the node you're setting it on is a Text node they will modify the text in the textnode directly instead of doing what the spec calls for (removing all the children and creating a new Text child). Hence the difference in mutation events.
Firefox's behaviour seems to be correct. You setting the innerHTML, so you do not change the characterData of an existing textNode, you insert a new textNode and remove any existing contents .(You may also observe DOMNodeRemoved in your example, you'll see that it fires too)
See the difference when really modifying the data of a textNode: http://jsfiddle/doktormolle/yQu8v/
本文标签:
版权声明:本文标题:javascript - DOMCharacterDataModified not firing consistently across Firefox and Chrome. Who is correct? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745408565a2657361.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论