Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how does looping using if work?

    Code:
    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
    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?
    Last edited by liorean; 06-08-2004 at 10:43 AM.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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
    {
    ...
    }

  • #3
    New Coder
    Join Date
    May 2004
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oh, silly me, forget to add the </a> after the <a> :P thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •