Tuesday, August 21, 2007

IE <pre> tag bug

For those of you searching for an answer to why IE doesn't handle whitespace properly in <pre> tags that have been updated with javascript by setting innerHTML, this is a bug in IE, and exists as of this date in version 7.

You can work around it by adding an additional <pre> </pre> in the innerHTML, so you have nested <pre>'s. That works. Or you can put the <pre> you want to update in a container <div> and update the innerHTML property of the container <div> instead.

The second approach seems to be the more correct way to handle this, but you'll have to re-attach any events to the new pre, because you're creating a new element instead of updating the old one.

No comments: