The following source code alerts the following results:
Internet Explorer 7: 29
Firefox 3.0.3: 37 (correct)
Safari
IE tries to be helpful and hides text nodes that contain only whitespace.
In the following:
W3C DOM spec says that has 3 child nodes ("\n", and "\n"), IE will pretend there's only one.
The solution is to skip text nodes in all browsers:
var node = element.firstChild;
while(node && node.nodeType == 3) node = node.nextSibling;
Popular JS frameworks have functions for such things.