I tested the following code snippet for IE, Chrome, and Firefox and wondered what caused the differences in the results.
var body = document.getElementsByTagName('body')[0]; body.innerHTML = '<div id="myId"><span>I am a text</span></div>'; var divElement = document.getElementById('myId'); console.log(divElement.children.length);
Unsurprisingly, in three browsers, after the second innerHTML change, the divElement no longer refers to the displayed <div> . I have no problem with this.
What I find more interesting is that IE seems to drop the divElement . Chrome and FF still allow me to work with the old tag and its children as if they were rendered, but IE turned the tag into an empty wrapper.
What is the difference in how the browser handles the innerHTML change that causes this behavior?
source share