Hi Norman,
In both nodestest and nodestest2 there is still some whitespace between the opening BODY tag and the opening DIV tag. In nodestest3 there is no whitespace there.
My second code post is not to show how it "should" be done, but rather just to illustrate how whitespace is represented as Text nodes in the DOM tree when the browser is in 'standards-compliant mode'.
If an element has an id, then by all means use "document.getElementById(idString)" to get a reference to the object.
There are times when we do need to traverse the DOM tree, and this when we need to remember that non-Element nodes may also be in the tree. For example in the following code the expression "oNode.nodeType == 1" checks to see if the node is of type ELEMENT_NODE instead of TEXT_NODE, COMMENT_NODE, etc. (reference: Node Interface)
Code:
/* xWalkTree()
Perform a preorder traversal
on the subtree starting at oNode
and pass each Element node to fnVisit.
*/
function xWalkTree(oNode, fnVisit)
{
if (oNode) {
if (oNode.nodeType == 1) {fnVisit(oNode);}
for (var c = oNode.firstChild; c; c = c.nextSibling) {
xWalkTree(c, fnVisit);
}
}
}
Why is it that in IE5.5 it works perfectly as long as the transitional doctype isn't included but falls over if the doctype is there? I could understand it if it was the strict doctype but ...
Reference IE6 Doctype Mode Switching. I'm not sure about how IE5.5 does this.
Edit:
replaced xWalkTree code with a version that's a little better commented
Bookmarks