DOM Tree menu..

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Angelos

    DOM Tree menu..

    Hello there.. I have the folowing piece of javascript that hides all my ul
    elements in a menu of the folowing structure:
    <ul>
    <li><a href="#">Page</a>
    <ul>
    <li><a href="#">Add</a></li>
    <li><a href="#">List</a></li>
    </ul>
    </li>
    <li><a href="#" >News</a>
    <ul>
    <li><a href="#">Add</a></li>
    <li><a href="#">List</a></li>
    </ul>
    </li>
    </ul>

    HEre is the Javascript:
    <script type="text/javascript">
    function menu()
    {
    uls=document.ge tElementById('n avMenu').getEle mentsByTagName( 'ul');
    for(i=0;i<uls.l ength;i++)
    {
    ul=document.get ElementById('na vMenu').getElem entsByTagName(' ul');
    for(x=0;x<ul.le ngth;x++)
    {

    if(!ul[x].getElementsByT agName('ul')[0])
    {
    hidem(uls[x]);
    }
    }
    }



    function show(uls)
    {
    uls.style.displ ay='block';
    }
    function hidem(uls)
    {
    uls.style.displ ay='none';
    }
    }
    // Check if the browser supports DOM, and start the script if it does.
    if(document.get ElementById && document.create TextNode)
    {
    window.onload=m enu;
    }
    </script>

    My question is that : do you know how I can make this ULs that I hide how I
    can make them apear onclick of the <ul><li><a> Links ?
    I wrote the function but I can't really figure out how to loop thru the
    specific <ul><li><a> ....

    Sorry for the long code ... and sorry for my newbie question...
    If you think that my whole script is wrong let me know ... But as it is it
    hides succesfully the ULs ...
    As you understand I want to create a simple Tree menu with CSS and DHTML or
    what ever it is called...

    Thanks


  • Matt Kruse

    #2
    Re: DOM Tree menu..

    Angelos wrote:[color=blue]
    > As you understand I want to create a simple Tree menu with CSS and
    > DHTML or what ever it is called...[/color]

    Why reinvent the wheel?

    (and others, using the same concept)

    --
    Matt Kruse




    Comment

    • Angelos

      #3
      Re: DOM Tree menu..

      > Why reinvent the wheel?[color=blue]
      > http://www.javascripttoolbox.com/mktree/
      > (and others, using the same concept)
      >
      > --
      > Matt Kruse
      > http://www.JavascriptToolbox.com
      > http://www.AjaxToolbox.com[/color]

      Ok Matt, THat was really what I wanted, but with one small problem.. When
      you click on a link the Menu Items Hide again... and I can't find a way
      fixing this problem...


      Comment

      Working...