M
Michael Hill
I am still having problems with the dom. blah ...
I have a table like:
<tbody id="list">
<tr>
<td>a</td> <td>b</td> <td>c</td> <td>d</td>
</tr>
</tbody>
To get the values "a", "b", "c", and "d" I have this code:
// get a list of all the tbody elements (there will only be one)
var my_tbody = document.getElementsByTagName("tbody").item(0);
//the first tr element under tbody
var my_row = my_tbody.getElementsByTagName("tr").item(0);
//the first td element under tr
var my_cell = my_row.getElementsByTagName("td").item(0);
//look at each td cell value
for( i=0; i<my_cell.childNodes.length; i++ )
{
mycelnode = my_cell.childNodes.item(i);
mytext = mycelnode.nodeValue;
alert(mytext);
}
To update the values to "x" I have this code:
//look at each value
for( i=0; i<my_cell.childNodes.length; i++ )
{
mycelnode = my_cell.childNodes.item(i);
mytext = mycelnode.nodeValue = "x";
}
This is not working. Any help is appreciated.
Mike
I have a table like:
<tbody id="list">
<tr>
<td>a</td> <td>b</td> <td>c</td> <td>d</td>
</tr>
</tbody>
To get the values "a", "b", "c", and "d" I have this code:
// get a list of all the tbody elements (there will only be one)
var my_tbody = document.getElementsByTagName("tbody").item(0);
//the first tr element under tbody
var my_row = my_tbody.getElementsByTagName("tr").item(0);
//the first td element under tr
var my_cell = my_row.getElementsByTagName("td").item(0);
//look at each td cell value
for( i=0; i<my_cell.childNodes.length; i++ )
{
mycelnode = my_cell.childNodes.item(i);
mytext = mycelnode.nodeValue;
alert(mytext);
}
To update the values to "x" I have this code:
//look at each value
for( i=0; i<my_cell.childNodes.length; i++ )
{
mycelnode = my_cell.childNodes.item(i);
mytext = mycelnode.nodeValue = "x";
}
This is not working. Any help is appreciated.
Mike