It seems that IE-11 cannot normalize elements that are already part of your document if the developer toolbar is open .
This is also true for IE9 and 10 (emulated using the meta http-equiv="X-UA-Compatible" tag meta http-equiv="X-UA-Compatible" )
When you create new nodes and do not add them to the document - everything works fine (for both situations - the developer toolbar is open and closed):
d = document.createElement('div'); d.appendChild(document.createTextNode('text 1')); d.appendChild(document.createTextNode('text 2')); console.log(d.childNodes.length + ' - Should be 2') d.normalize(); console.log(d.childNodes.length + ' - Should be 1')
If, however, you are working with nodes that are already part of your document, the normalize function does not work if the developer toolbar is open :
d = document.getElementsByTagName('div')[0]; d.appendChild(document.createTextNode('text 1')); d.appendChild(document.createTextNode('text 2')); console.log(d.childNodes.length + ' - should be 2 on every browser') d.normalize(); console.log(d.childNodes.length + ' - should be 1, however it\ 2 on IE')
<div></div>
If you really want to, then you can extract the nodes from the document and add them after normalizing them:
d = document.getElementsByTagName('div')[0]; d.appendChild(document.createTextNode('text 1')); d.appendChild(document.createTextNode('text 2')); console.log(d.childNodes.length + ' - should be 2 on every browser') dNew = d.cloneNode(true) dNew.normalize() d.parentElement.replaceChild(dNew, d) d = document.getElementsByTagName('div')[0]; console.log(d.childNodes.length + ' - should be 1 on every browser')
<div></div>
Update - 28/8
The answer was updated after a comment from @dude. It took some time to investigate the cause here, but I think that now I have covered everything.
Please note that for IE8 (forcibly using <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8"> in IE-11), the normalize() function works for both elements that are in the DOM tree , and elements that are not, even with the developer panel were open.
Dekel source share