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.net/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.org/show_bug.cgi?id=368133 and the W3 docs (http://www.w3.org/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.
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.net/doktormolle/yQu8v/