Internet Explorer innerHTML problem while adding rows in table with javascript
If you are a web developer and work with js/AJAX, surely you would have faced a situation like this.
I had a table in a page. What i had to do was create rows in javascript and set the innerhtml of table to the rows created. Something like this-
var x=""; var tableContents=" <tbody>"; for(var i=0;i<5;i++) { x+=" <tr>" x+=" <td>row"+(i+1)+"</td> " x+="</tr> " } x+="</tbody> "; document.getElementById("myTable").innerHTML = x;
of course assuming myTable is the table element available in the page.
I prefer innerHTML over DOM functions as they are faster on all browsers and platforms.
Anyway, I checked above code and found that it worked perfectly in all browsers (firefox, opera …) except IE (http://www.schneier.com/blog/archives/2005/12/internet_explor.html).
No error and nothing, my table was still empty.
Well, after many undsuccessfull attempts with innerHTML,I tried google and came up with this.
http://msdn.microsoft.com/en-us/library/ms533897(VS.85).aspx
It clearly says-
“The property is read/write for all objects except the following, for which it is read-only: COL, COLGROUP, FRAMESET, HEAD, HTML, STYLE, TABLE, TBODY, TFOOT, THEAD, TITLE, TR. The property has no default value.”
I dont know why they have done this but thats the way IE is.
So keep in mind the next time you have to do something like this.
Related Posts
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.


thanks for this helping article.
This problem really puzzles. You’ve done very good analysis. Keep it up Man!
[...] this time: Last time it was appending rows to an existing table. Now it wont let you set innerhtml of a select box through javascript [...]
[...] I am tired of making web applications work on IE. I can understand the frustration of this guy who created a pie chart for breakdown of time spent in web development. Making an application work on IE takes most of the time. Be it the issue of setting innerHTML of select or setting innerhtml or rows. [...]