...

View Full Version : how does looping using if work?



guowei1000
06-08-2004, 05:49 AM
for (var i = 0; i < level; i++) {
indent = indent + "&nbsp;&nbsp;&nbsp;&nbsp;";
}


if (node.nodeName == "#text")
{
strContent = strContent + indent + "ChildrennodeText = " + node.text
+ "<br/>";
}
else
{
var check = node.nodeName
strContent = strContent + indent + "<A onClick=javaScript:toogle_state(check)><font color=blue>nodeText = " + node.nodeName + "<br/>";

}

strContent = strContent + "<p>";

}
if (node.firstChild) {
crawl(node.firstChild, level + 1);
}
if (node.nextSibling) {
crawl(node.nextSibling, level);
}
strContent = strContent + "</p>";
}
The code should be longer but i just cut this part out save space :D
i know it loop then check but does the If work?
when i try out the code out every thing turn blue shouldnt it only turn the <font color=blue> into blue? help pls?

glenngv
06-08-2004, 06:22 AM
if-conditions don't loop. And the if-condition in the snippet you posted is outside the for-loop. To test where the condition goes, put an alert before it.

alert(node.nodeName);
if (node.nodeName == "#text")
{
...
}
else
{
...
}

guowei1000
06-08-2004, 09:06 AM
oh, silly me, forget to add the </a> after the <a> :P thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum