keesvanbreukelen
Programmer
I have great difficulty with firstChild method and the childNodes collection in Firefox, the following sample code works well in IE but not at all in Firefox, when I check the Javascript bible it looks like it is perfectly standard DOM handling.
Sample:
<html>
<head>
</head>
<body>
<center>
Why does this work in IE but not in Firefox?
<br /><br />
<table id = "table">
<tr id = "row1">
<td id = "col1">Hello There</td>
</tr>
</table>
<br /><br />
<input type = "button" value = "show table innerHTML" onclick = "document.getElementById('tablehtml').value=document.getElementById('table').innerHTML;" />
<br /><br />
<input type = "button" value = "alert(document.getElementById('table').firstChild.firstChild.id should display: row1)" onclick = "alert(document.getElementById('table').firstChild.firstChild.id)" />
<br />
<br />
<br />
<input type = "button" value = "alert(document.getElementById('row1').firstChild.id should display: col1)" onclick = "alert(document.getElementById('row1').firstChild.id)" />
<br /><br />
<textarea id = "tablehtml" rows = "4" cols = "60"> </textarea>
</center>
</body>
</html>
Sample:
<html>
<head>
</head>
<body>
<center>
Why does this work in IE but not in Firefox?
<br /><br />
<table id = "table">
<tr id = "row1">
<td id = "col1">Hello There</td>
</tr>
</table>
<br /><br />
<input type = "button" value = "show table innerHTML" onclick = "document.getElementById('tablehtml').value=document.getElementById('table').innerHTML;" />
<br /><br />
<input type = "button" value = "alert(document.getElementById('table').firstChild.firstChild.id should display: row1)" onclick = "alert(document.getElementById('table').firstChild.firstChild.id)" />
<br />
<br />
<br />
<input type = "button" value = "alert(document.getElementById('row1').firstChild.id should display: col1)" onclick = "alert(document.getElementById('row1').firstChild.id)" />
<br /><br />
<textarea id = "tablehtml" rows = "4" cols = "60"> </textarea>
</center>
</body>
</html>