IE8 not supporting innerHTML

consider this javascript snippet:

document.getElementById('optionsTable').innerHTML = '<tr><th>Option</th><th>Price</th><th>Stock</th></tr>';

There is a table on the page with id="optionsTable", and the table has always loaded before the function is called.

This piece if javascript was being called to reset a table that allows option/price/stock information to be given to products. It works in Opera and Firefox (and probably IE 6, possibly IE 7) but it doesn't work in IE 8 .

Does IE 8 restrict your manipulation of the DOM to some extent? I can only assume that is does, as I was able to achieve the same effect (in albeit a slightly less hacky way than using innerHTML) like this:

var tmpNumRows = document.getElementById('optionsTable').rows.length;

So there was nothing wrong with my table, and IE was happy for me to mess around with it via DOM manipulation, it just wanted me to do it properly rather than abusing innerHTML. So while this was quite irritating as it created a bit of work, it was certainly an enlightening exercise. Does this mean that IE's DOM / javascript engine is stricter than the other browsers?

Post a comment