I am appending trs to a table from a string. I use the following code to write an entire table using innerHTML, then I can use standard DOM to transfer the new bits to the existing table.
var div = document.createElement("div");
div.innerHTML = "<table><tbody>" + string + "</tbody></table>";
Using the following simple Javascript is fine, until we look at CSS styling. This causes each section to be in a different tbody. This is not acceptable as CSS styling is using :nth-child(odd)
document.getElementById("left").appendChild(div.firstChild.tBodies[0]);
Thus, I have changed the code to this, but it is only adding every other row to the table. What did I do wrong?
var tableBody = div.firstChild.tBodies[0];
var appendToTable = document.getElementById("left").tBodies[0];
var totalnodes = tableBody.childNodes.length;
for (var thenodes = 0; thenodes < totalnodes; thenodes++) {
appendToTable.appendChild(tableBody.childNodes[thenodes]);
}