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
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to count nested levels in a list?

    I'm having a bad brain day ... feels like this should be really obvious, but I can't see it ..

    Given an unordered-list with an unknown number of nested lists, how would I find the deepest number of levels it goes to?
    Last edited by brothercake; 07-24-2003 at 07:59 PM.
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    function recursion(depth,element)
    { currentDepth = depth + 1;
    for(var i=0; i<element.childNodes.length; i++)
    { if(condition)
    { newDepth = recursion(currentDepth,element.childNodes[i]);
    currentDepth = newDepth>currentDepth?newDepth:currentDepth;
    }
    }
    return currentDepth;
    }


    recursionDepth = recursion(0,topelement);

    It's late in the afternoon and my brain as tired too, but this should give you the depth of recursion...
    Last edited by Vladdy; 07-24-2003 at 08:22 PM.
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wickde; thanks
    "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark


  •  

    Posting Permissions

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