R
Rex the Strange
BIG WARNING!!
I just spent hours trying to figure this out! If you're doing dynamic
javascript and you're trying to create a table on the fly using
createElement then HEED THIS WARNING!
You would think that you could get away with this:
var page_element = document.getElementById ("parent_element_name");
var table = document.createElement ("table");
var row = document.createElement ("tr");
var cell = document.createElement ("td");
page_element.appendChild (table);
table.appendChild (row);
row.appendChild (cell);
cell.innerHTML = "this is where the live stuff goes";
And Firefox has no problems with this. Internet Explorer will puke!
Well, actually, IE does nothing at all and you can poll your page for
the elements and you will find them. They're there, but they don't
show up on the page. You need:
var body = document.createElement ("tbody"); (or thead or tfoot)
Link that to the table and the row to that:
table.appendChild (body);
body.appendChild (row);
And everything is hunky dorey! I just wasted a big piece of my life on
this one so I'm hoping I can save some people the same heartache. By
the way, Firefox doesn't care either way, so use the latter for better
cross-browser compatibility (also works in Opera and PC Safari - don't
know about Mac Safari).
I just spent hours trying to figure this out! If you're doing dynamic
javascript and you're trying to create a table on the fly using
createElement then HEED THIS WARNING!
You would think that you could get away with this:
var page_element = document.getElementById ("parent_element_name");
var table = document.createElement ("table");
var row = document.createElement ("tr");
var cell = document.createElement ("td");
page_element.appendChild (table);
table.appendChild (row);
row.appendChild (cell);
cell.innerHTML = "this is where the live stuff goes";
And Firefox has no problems with this. Internet Explorer will puke!
Well, actually, IE does nothing at all and you can poll your page for
the elements and you will find them. They're there, but they don't
show up on the page. You need:
var body = document.createElement ("tbody"); (or thead or tfoot)
Link that to the table and the row to that:
table.appendChild (body);
body.appendChild (row);
And everything is hunky dorey! I just wasted a big piece of my life on
this one so I'm hoping I can save some people the same heartache. By
the way, Firefox doesn't care either way, so use the latter for better
cross-browser compatibility (also works in Opera and PC Safari - don't
know about Mac Safari).