Yet Another Javascript Incompatibility

This one’s only minor but got me for a bit a while back…

If you’re trying to add rows to a table you’d naturally do something like this:

var tbl = document.getElementById("myTable");
var row = document.createElement("TR");
var cell = document.createElement("TD");

<table id="myTable">

That will work fine in FireFox but not in IE. The reason is simple: IE automatically adds a TBODY element to your table and expects rows to be added to that instead. So the solution is simple. Change your HTML to:

    <tbody id="myTable">

Then both FF and IE work fine. Maybe I was just being a bit slow when I had that problem.

This entry was posted in Computers and Internet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s