Hey everybody,
I am having a problem here - I get two different result from NS and IE ( to be exptected I guess ). I am using DOM so I expect to work on both browsers but I am wrong. Below is a sample - What I am trying to do is get the next row of a table when an item in the the previous row was clicked in one of the cells - yeah... Anyway, IE works as I anticipated but NS is tripping on it. Is there a problem with NS DOM nextSibling? The problem part is in red and NS returns an "undefined."

Whitespace nodes are included in Mozilla's DOM. Perhaps nextSibling is a whitespace node instead of an element.

Echo88

08-09-2004, 08:48 PM

Ok - but why would it return an "undefined" value? As if it is returning null. Is TR considered a whitespace node.

Is there a better way of tranversing through the DOM.

jkd

08-09-2004, 09:39 PM

The "id" property is not defined on a whitespace node, therefore it is "undefined".

brothercake

08-13-2004, 04:14 AM

You can go two ways - well three ways, but the third is ugly:

1 - don't rely on sibling relationships - look for elements using getElementsByTagName - this is very simple and effective, although slightly less efficient overall

2 - clean the whitespace before you start - Alex Vincent wrote a function for that: http://www.codingforums.com/showthread.php?t=7028 This works admirably to normalise any DOM, but don't allow it to run in Mac/IE5, because in that browser HTML structures become unstable when stripped of whitespace (weird rendering bugs start happening)

3 - every time you look for a sibling node you can check if it's a text node using "nodeName" - a text node returns "#text" - if it is then you can deem the node you want to be either the next or previous sibling, depending on which way you're going. This is tedious and will drive you insane ...

I don't see why you simply don't check the node type. It's a rather simple process:
var
objParSibling=objParent;
do
objParSibling=ObjParSibling.nextSibling;
while(objParSibling.nextSibling!=null&&objParSibling.nodeType>1);