I have created a function that successfully appends a table with rows/cells and populates them from an array. The problem is that they are being appended to the top of the table.
It is doing this because the line var row = tbody.insertRow(r);
...I think/hope.
The function to look at in the link below is appendTable(id)
Here is the working example that appends to the top: http://jsfiddle.net/JEAkX/4/
I was thinking something like this would work: var row = insertRow(r).appendTo('tbody>tr:last');
however it just broke the function.
I also tried MANY different combinations of .append()
and .appendTo()
on that same line with no success.
As a last ditch effort I tried variations on the linecell.innerHTML = "<input type='text' size='1' value='" + subset[i++] + "' />"
but I believe by that time the location is already decided.
Here is the function extracted from the example:
function appendTable(id)
{
var tbody = document.getElementById(id).getElementsByTagName("tbody")[0];
var i = 0;
for (var r = 0; r < 2; r++) {
var row = tbody.insertRow(r);
for (var c = 0; c < 4; c++) {
var cell = row.insertCell(c);
cell.innerHTML = "<input type='text' size='1' value='" + subset[i++] + "' />"
}
}
}
On a side not I tried (unsuccessfully) insertAfter
at one point but read that I would not be able to use it on something that didn't exist on page load.