DOM Tree menu..

A

Angelos

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.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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top