document.createElement in IE with TR tag

R

rain_c1

Hi!

I have problems with document.createElement() in IE when using TR tags.
Please look at the following very short example:

------------snip-----------------
<table id="test"></table>

<script type="text/javascript">
var MyTable = document.getElementById("test");
var myTR = document.createElement('tr');
var myTD = document.createElement('td');
var myText = document.createTextNode("this is text");

myTD.appendChild(myText);
myTR.appendChild(myTD);
MyTable.appendChild(myTR);
</script>
------------snip-----------------

this works fine in Firefox, but IE is very strange. It refuses to
display the created elements. Through further tests I realized, that
only the TR tag is the problem. If this is already in the static HTML
code it works in IE, too.

Further very strange: If I use the developer toolbar for IE and use the
DOM Explorer, it shows me, that all my dynamic generated tags are
there, but they are not displayed.

Has anybody an idea?

Thank you very much!

Best regards,
- Rainer
 
M

Matt Kruse

var MyTable = document.getElementById("test");

Get a reference to the tbody element instead of the table element.
When you don't explicitly put one in, IE puts one in for you.
A TR can only be appended to a tbody.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top