views:

93

answers:

2

Please see this:
http://jsbin.com/igeqa

here, i am simply using

alert ( tableObj.childNodes.length );

and in FF the output is 5 , while in IE it is 2. Please tell me what is causing this behaviour?

+11  A: 

Firefox counts whitespace text nodes, while IE is just counting elements. So Firefox is returning [#text, THEAD, #text, TBODY, #text], while IE is returning just [THEAD, TBODY].

Annie
awesome! accepted. does that mean we should not reply on `childNodes` property
Rakesh Juyal
It's fine to rely on childNodes, just check for "node.nodeType == 1" (element nodes) in the code that processes the childNodes to make sure they're elements if you don't want to get text nodes, comment nodes, etc.
Annie
thanks, i will use getElementsBytagName instead of childNodes
Rakesh Juyal
+1  A: 

IE and Moz count the childNodes in a HTML document in different ways. Moz counts every empty space (possible textNodes) as a childNode, while IE counts only some of them. There are several solutions for that.

Sarfraz
`404 - File not found`
Rakesh Juyal