Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Netscape childNode.length--what is it?

Status
Not open for further replies.

jsteph

Technical User
Oct 24, 2002
2,562
US
Hi,
I've noticed that NN (7.2 in my case) seems to count *all* nodes anywhere below the node in question as part of the childNodes.length property.

For instance, I have a <table> with <tr> which has, say, 10 <td>'s and in each <td> there is an <input>. IE 6 counts the tr.childNodes.length as 10, but NN counts 20. Obviously this messes up code that tries to use this, which I thought was a DOM standard. I was under the impression that both ie6 and nn7 were compliant with the DOM standards. Is this not the case? And which one is breaking the standard? And is there another syntax I might use that would be at least compatible with ie and nn, specifically for navigating table objects and their nodes.
Thanks for any help on this.
--Jim

 
Did you check the child nodes (in your example) at all? I know it was just an example... but using your real data did you check what the nodes actually were?

I am picking that there will always 2x the amount as reported in IE. I noticed that some browsers add in a text node to account for any whitespace. It appears that IE ignores whitespace -- whilst NS doesn't (as we all know from trying to get "old school" table layouts to work accurately all the time).

You could always strip all whitespace from your source, I guess *lol*

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Jeff,
I looked at the innerHTML of the row object, and they're basically identical--NN and IE differ in where the put the attributes, for example, regardless of how you write the source html, the innerHTML might have, say, the id='mynodename' in a different spot in NN, but all the pieces are there and NN has no 'surprise' stuff.

I did a
Code:
window.alert(rowobject.childNode[2].id +  ' ' +rowobject.childNode[2].innerHTML + ' ' + rowobject.childNode[2].name)
and it's 'undefined undefined undefined'
(I chose ordinal 2 because it's the even ones in NN that are the 'ghost' nodes)

So it's baffling me. So I did:
Code:
window.alert(rowobject.childNode[2].childNodes[0].id)
and in IE it (correctly) returns the id of the <input> within the <td> at ordinal 2 in the row object. In NN I get the error
"rowobject.childNode[2].childNodes[0] has no properties"

This is just insane. I don't know which browser is 'right' but I wish they could all be at least close to compatible.
--Jim
 
Instead of alerting ".innerHTML", you should instead alert ".nodeType".

Text nodes have no innerHTML property, so I would expect them to return "undefined". Alerting the node type will at least tell you if Jeff is right (i.e. they are text nodes).

P.S. Further discussion on this should probably be done in the JavaScript forum (forum216).

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top