mf22cs
05-06-2003, 06:09 PM
The following code is an extract from a bigger HTML-document.
It works just fine in Internet Explorer 6.0. But as always, it does not work properly under Netscape 7.02. :(
Can anyone tell me whatīs wrong... kind of newbie to this DOM-thing.
Yes, the code below is some what modified to you reflect the problem. That it is something strange whit Netscape and the use of "firstChild" in DOM. :cool:
/Marcus
<html>
<head>
<title>testar strul med DOM i Netscape</title>
<script language="JavaScript">
<!--
function init() {
var tab;
var scoreP1 = 10; // In the real game this is not set by hand...
var scoreP2 = 0; // In the real game this is not set by hand...
/************************
** FOR DEBUG ONLY **
************************/
alert(document.getElementById("endTable").nodeName);
// The above gives: In IE & NS -> TABLE (Thatīs OK).
alert(document.getElementById("endTable").firstChild.nodeName);
// The above gives: In IE -> TBODY / In NS -> #name (Not OK)
alert(document.getElementById("endTable").firstChild.firstChild.nodeName);
// The above gives: In IE -> TR / In NS -> (nothing at all)
alert(document.getElementById("endTable").firstChild.firstChild.firstChild.nodeName);
// The above gives: In IE -> TD / In NS -> (nothing at all)
/************************
** END OF DEBUG **
************************/
tab = document.getElementById("endTable").firstChild.firstChild;
tab.firstChild.innerHTML="The match is over";
tab = tab.nextSibling;
tab.firstChild.innerHTML="Player 1";
tab.firstChild.nextSibling.innerHTML=scoreP1;
tab = tab.nextSibling;
tab.firstChild.innerHTML="Player 2";
tab.firstChild.nextSibling.innerHTML=scoreP2;
tab = tab.nextSibling;
tab.firstChild.innerHTML="Text1";
tab.firstChild.nextSibling.innerHTML="Text2";
}
// -->
</script>
</head>
<body onload="setTimeout('init()',3000);">
<table id="endTable" border="1">
<tbody>
<tr width="100%">
<td align="center" colspan="2">1</td>
</tr><tr>
<td width="50%" align="center">2</td>
<td width="50%" align="center">3</td>
</tr><tr>
<td width="50%" align="center">4</td>
<td width="50%" align="center">5</td>
</tr><tr>
<td width="50%" align="center">6</td>
<td width="50%" align="center">7</td>
</tr>
</tbody>
</table>
</body>
</html>
:mad: :( :( :(
It works just fine in Internet Explorer 6.0. But as always, it does not work properly under Netscape 7.02. :(
Can anyone tell me whatīs wrong... kind of newbie to this DOM-thing.
Yes, the code below is some what modified to you reflect the problem. That it is something strange whit Netscape and the use of "firstChild" in DOM. :cool:
/Marcus
<html>
<head>
<title>testar strul med DOM i Netscape</title>
<script language="JavaScript">
<!--
function init() {
var tab;
var scoreP1 = 10; // In the real game this is not set by hand...
var scoreP2 = 0; // In the real game this is not set by hand...
/************************
** FOR DEBUG ONLY **
************************/
alert(document.getElementById("endTable").nodeName);
// The above gives: In IE & NS -> TABLE (Thatīs OK).
alert(document.getElementById("endTable").firstChild.nodeName);
// The above gives: In IE -> TBODY / In NS -> #name (Not OK)
alert(document.getElementById("endTable").firstChild.firstChild.nodeName);
// The above gives: In IE -> TR / In NS -> (nothing at all)
alert(document.getElementById("endTable").firstChild.firstChild.firstChild.nodeName);
// The above gives: In IE -> TD / In NS -> (nothing at all)
/************************
** END OF DEBUG **
************************/
tab = document.getElementById("endTable").firstChild.firstChild;
tab.firstChild.innerHTML="The match is over";
tab = tab.nextSibling;
tab.firstChild.innerHTML="Player 1";
tab.firstChild.nextSibling.innerHTML=scoreP1;
tab = tab.nextSibling;
tab.firstChild.innerHTML="Player 2";
tab.firstChild.nextSibling.innerHTML=scoreP2;
tab = tab.nextSibling;
tab.firstChild.innerHTML="Text1";
tab.firstChild.nextSibling.innerHTML="Text2";
}
// -->
</script>
</head>
<body onload="setTimeout('init()',3000);">
<table id="endTable" border="1">
<tbody>
<tr width="100%">
<td align="center" colspan="2">1</td>
</tr><tr>
<td width="50%" align="center">2</td>
<td width="50%" align="center">3</td>
</tr><tr>
<td width="50%" align="center">4</td>
<td width="50%" align="center">5</td>
</tr><tr>
<td width="50%" align="center">6</td>
<td width="50%" align="center">7</td>
</tr>
</tbody>
</table>
</body>
</html>
:mad: :( :( :(