469,306 Members | 1,901 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

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.getElementById('navMenu').getElements ByTagName('ul');
for(i=0;i<uls.length;i++)
{
ul=document.getElementById('navMenu').getElementsB yTagName('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
Jul 23 '05 #1
2 2839
Angelos wrote:
As you understand I want to create a simple Tree menu with CSS and
DHTML or what ever it is called...


Why reinvent the wheel?
http://www.javascripttoolbox.com/mktree/
(and others, using the same concept)

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jul 23 '05 #2
> Why reinvent the wheel?
http://www.javascripttoolbox.com/mktree/
(and others, using the same concept)

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


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...
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jo | last post: by
7 posts views Thread by johkar | last post: by
4 posts views Thread by Sergio Millich | last post: by
reply views Thread by Tree menu using XML | last post: by
4 posts views Thread by Tarique Jawed | last post: by
1 post views Thread by Jesper DK | last post: by
1 post views Thread by w.p. | last post: by
6 posts views Thread by Travis | last post: by
3 posts views Thread by Travis | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.