Friday, March 6th, 2009

Fun Anecdote about innerHTML

Category: IE

Just when you started having fun with innerHTML, you discovered that on IE, various table-related elements can’t be modified with it. Ever wonder why? Eric Vasilik is the developer responsible for that “feature” of IE, and he came clean about it several years ago:

We never had enough time to implement such a feature. And, in order to deal with attempts to modify tables in such a manner, I prohibited the modification of tables with innerHTML and other methods.

An alternative to all this would have been to “hack” something up. For example, I could have checked to see if the innerHTML of a TBODY was being set to something which began with a “

“. Under these circumstances I could have prepended a “

” to the string, and then plucked the TR’s out of the resulting tree and replaced the contents of the TBODY with them.

Sounds simple enough until you have to consider all the variations. Like, what if the string to be parsed looks like “

…”. Pretty soon you start doing all the work the real parser has to do.

So instead of hacking up something very incomplete and possibly erroneous in many cases, I left the modifications of tables with innerHTML out of the product.

The full blog entry goes into a bit more detail and is fairly interesting. Also, be sure to check out the post on easter eggs in early versions of IE.

Posted by Ben Galbraith at 8:00 am

3.3 rating from 27 votes


Comments feed TrackBack URI

The real crime isn’t omitting innerHTML for tables umpteen years ago, it’s that Microsoft has never implemented it since. And I’ve got the world’s smallest violin playing just for that Microsoft developer who got bit by his own omission.

Comment by JonathanLeech — March 6, 2009


Oh snap.

Comment by igaenssley — March 6, 2009

For anyone who cares and doesn’t want to bother viewing the source, the tags that were not properly escaped in the quote are:

<!– new rows –>

I’m continually rolling my eyes at basic mistakes like this on a site devoted to advanced web development concerns.

Comment by eyelidlessness — March 6, 2009

Oh, and of course the comment parser can combine two hyphens to become an em dash. 9_9

Comment by eyelidlessness — March 6, 2009

yeah, as the old saying goes—on the high seas, before a judge, and when commenting on a blog post, your fate is in god’s hand. looks like nearly all the blog software out there has been designed to shoot down some other randomly chosen feature of what you typed in. last time i looked, slashdot of all places TURNED ANY CHARACTER OUTSIDE OF LATIN-1 INTO UTF-8 LITERALS!!!!!!!!!!!!!!!!

sorry for shouting.

Comment by loveencounterflow — March 7, 2009

Leave a comment

You must be logged in to post a comment.