EDIT: This isn\'t happening because of the ajax call. I changed it to use a value from a TinyMCE component for fun and I get the same thing.
content = tinyM
I would like to extend the answer, as of why is happening, and provide a workaround. Doing a GreaseMonkey script i was trying to change the content of an element, perhaps not changing per se but adding more elements as the tag had only an IMG inside.
Original:
What i tried to do was to insert a DIV element that would wrap the already IMG and another new SPAN second child, so the objetive was to end up with this:
text
Using the innerHTML property it would be like this:
ANode.innerHTML = '' + ANode.innerHTML + 'text';
but instead i got:
Looking at the answers here did help a bit although there's no real explanation. After a while i noticed something that does not happens with the example in the question, which now i believe is the key to this issue. I was the same as jfrobishow thinking where was it happening, i thought there was something wrong concatenating the ANode.innerHTML.
Answering, at the original question, the part of narrowing it down to where does this happens, notice that the out-of-nowhere was enclosing both the IMG and the new SPAN nodes, so this made me curious, the unwanted was being added just before the DIV element was "built". So from this, the original example, and my following workaround you can notice that this happens when you insert a new BLOCK node inside an Anchor, as both DIV and P (original example) elements are BLOCK elements.
(If you don't know what i mean by BLOCK is from the display property of an element http://www.w3schools.com/cssref/pr_class_display.asp)
The obvious workaround is to replace the type of node you're inserting, to a non-block element, in my case the problem was the DIV i wanted, but of course it depends on the objective of your script, most of the things are there by design, i put a DIV because i needed it, so i fixed it turning that DIV into another SPAN ( which is an inline element) but i still needed to behave like a block element so put the style, this is what worked for me:
ANode.innerHTML = '' + ANode.innerHTML + 'text';
So, plainly, this problem is not from scripting (Javascript for me) but from style (CSS) stuff. BTW, this happened at Firefox 3.6.18, notice this does not happens at Firefox 5.0.