Yet another IE bug - innerHTML of a PRE does not preserve whitespace

Posted by james on Jan 28, 2010 12:00 AM

I was working on Monkey Analytics when I noticed this bug:
<pre id="some-pre">This
should
appear
on
separate
lines.</pre>

This is fine, but when you do this in IE7:
<script>
document.getElementById('some-pre').innerHMTL = document.getElementById('some-pre').innerHMTL;
</script>

It strips all the whitespace out, putting everything on a single line. Why? In all other browsers, innerHTML returns the contents of a PRE. In IE7, innerHTML returns the contents with all whitespace consolidated and altered, so there are no linebreaks.

So this is yet another IE bug. What a giant pile of crap. It's hard to imagine any serious web developer voluntarily using IE to do anything.

Thanks to this blog post for confirming what I've seen.