mx*@yahoo.com wrote:
Hi,
given table :
<table id='t1'>
<tr><td> data1</td><td>data2</td></tr>
</table>
i would like to write a function to write and change data2
( location is fixed ).
function changeme () {
document.write('new data2');
}
how can I focus on 'data2' before calling the above function?
thanks
Michael
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<script type="text/javascript">
//<![CDATA[
function changeme()
{
var tbl = document.getElementById('t1'); //table
var firstrow = tbl.rows.item(0); //row 1 (DOM: 0)
var cell2 = firstrow.cells.item(1); //2nd TD
while (cell2.hasChildNodes()) //anything in there?
cell2.removeChild(cell2.lastChild); //adios
cell2.appendChild(document.createTextNode('new data2')); //new text
node, add
}
onload = function()
{
setTimeout(changeme, 3000);
}
//]]>
</script>
</head>
<body>
<table id="t1" cellspacing="10">
<tbody style="font:32px tahoma;">
<tr>
<td>data1</td>
<td>data2</td>
</tr>
</tbody>
</table>
</body>
</html>
http://www.sitepoint.com/article/rough-guide-dom