strauchdieb wrote on 07 okt 2006 in comp.lang.javascript
:
oh sorry, i've totally forgotten to post the code. sorry...
here's the code:
for (var i = 0; i < tableBody.rows.length; i++)
{
var cell = document.createElement("td");
tableBody.rows[i].appendChild(cell);
}
that's nothing fancy, i think.
i tested it with IE and firefox
Since you did not quote, we have to search back to your Q.
Please always quote on usenet.
it was:
i'm a little frustrated. i'm trying to add a td element with
appendChild as last child to a tr element. but it adds the td element
always as first child to the tr element?
although appendChild should add the new child at the end. what could be
wrong?
Nothing is wrong, try the following:
<table id='tableBody' border='1'>
<tr><td>mmmmm
<tr><td>mmmmm
<tr><td>mmmmm
<tr><td>mmmmm
</table>
<script type='text/javascript'>
var tableBody = document.getElementById('tableBody')
for (var i = 0; i < tableBody.rows.length; i++){
var cell = document.createElement("td");
tableBody.rows[i].appendChild(cell);
cell.innerHTML = 'Hello!'
}
</script>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)