DOM Tree menu..
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

DOM Tree menu..

From: Angelos <adevletoglou@redcatmedia.net>
Date: Wed Jul 06 2005 - 20:07:33 CEST

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

HEre is the Javascript:
<script type="text/javascript">
function menu()
{
 uls=document.getElementById('navMenu').getElementsByTagName('ul');
 for(i=0;i<uls.length;i++)
 {
  ul=document.getElementById('navMenu').getElementsByTagName('ul');
  for(x=0;x<ul.length;x++)
  {

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

 function show(uls)
 {
  uls.style.display='block';
 }
 function hidem(uls)
 {
  uls.style.display='none';
 }
}
// Check if the browser supports DOM, and start the script if it does.
if(document.getElementById && document.createTextNode)
{
 window.onload=menu;
}
 </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
Received on Tue Oct 18 02:52:35 2005