Wednesday, August 11, 2010

IE8 dynamically created tables

I had to generate tables and append them to DOM dynamically (on ajax data requests responded).

IE8 acted as a bad-ass teacher to me, cuz I forgot to use tbody tag. So hopefully that helps:

BAD code:
var table = document.createElement("table");
var tr = document.createElement("tr");
table.appendChild(tr);
...
document.appendChild(table);

GOOD code:
var table = document.createElement("table");
var tbody = document.createElement("tbody");
var tr = document.createElement("tr");
tbody.appendChild(tr);
table.appendChild(tbody);
...
document.appendChild(table);

Otherwise IE ignores the content of your table and shows it with zero height and zero width.

I should mention, that IE8's Developer Tools did help me to find that out ;)

Niivisi

No comments:

Post a Comment