In my experience, most of the time the browser tries to fix HTML 1 before injecting it into the DOM. If you want to build <ul> as follows:
someElement.innerHTML += '<ul>'; someElement.innerHTML += '<li>some li</li>'; someElement.innerHTML += '<li>some other li</li>'; someElement.innerHTML += '</ul>';
In particular, Chrome, which would lead to:
<ul></ul> <li>some li</li> <li>some other li</li> <ul></ul>
So, innerHTML can give unpredictable results, because every time you use it, the HTML is adjusted by the browser (and browsers differ in how they do it). This is especially true for table / table elements (and even more so in IE (MS came up with innerHTML way;)). If you want your html to be exactly what you expected it to, stick to the DOM methods ( createElement / appendChild , etc.) Or first create a line of the full element that you want to insert using innerHTML, then in other words, don't use innerHTML with lines containing incomplete HTML.
To be complete, I quote the PPC quirksmode :
If you delete elements via innerHTML in IE, their contents are wiped and only the element itself (i.e. opening and closing labels) remains. If you want to remove nodes that you might want to reinsert later, use DOM methods such as RemoveChild ()
1 is more technical: I think that every browser uses its own HTML fragment analysis algorithm .
source share