...

Internet Explorer appendChild problem

Kenoshi
07-19-2010, 07:02 PM
I am making a web page, and as part of it I have a table that the user can add rows to. My code works in FF and Chrome, but IE is broken.
function addrow() {
var example=document.getElementById("new");
var addHere=document.getElementById("ticketTable");
var node= example.cloneNode(true);
node.id="added";
addHere.appendChild(node);
}

This code is called when a button is clicked. new is the ID of the row I am adding, and ticketTable is the ID of the table I am adding to. Help please!

RandomUser531
07-19-2010, 07:15 PM
new is the ID of the row I am adding, and ticketTable is the ID of the table I am adding to. I suspect that I.E. would expect a row to be appended to a tbody element, not the table directly. Also you should add an incrementing numeric suffix to the ID attribute so that it cannot be duplicated.

Old Pedant
07-20-2010, 01:40 AM
I suspect that I.E. would expect a row to be appended to a tbody element, not the table directly.
Most definitely.

SO you can do:

var addCount = 0;
function addrow() {
var example=document.getElementById("new");
var addHere=document.getElementById("ticketTable").getElementsByTagName("tbody")[0];
var node= example.cloneNode(true);
node.id="added" + (++addCount);
addHere.appendChild(node);
}

This does work in other browsers, so you don't have to do browser detection.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum