Click to See Complete Forum and Search --> : Trouble whit Netscape again


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: :( :( :(

khalidali63
05-06-2003, 08:32 PM
an empty node is considered a text node,therefore when you have
<td></td>
then
node 1 is td and node 2 will be the text node,in my understanding that is correct DOM behaviour....(could be wrong),you might have to change your logic to accomplish what you are trying to dd.

mf22cs
05-07-2003, 03:10 AM
I donīt get it, in the code I donīt have any empty node... have I :confused:

I could mixed things up... but...

In my point of wiev a empty node is, e.g. <hr>, <br>, <img> a.s.o. because ther is no <hr>Text</hr> there Text is handled in a way that is desided by the surrounding tags.

<td> on the other hand is at non-empty node, since there is a <td>Text</td>.

But then again, I could be wrong... maybe empty node is not the same in HTML/XHTML and DOM.

/Marcus