473,395 Members | 1,418 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 3035
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jo | last post by:
I don't know if this can be done.. But here is what i am trying to do... I have a tree menu on a frameless page. I have the menu on the right hand side and a CGI web form post on the left....
7
by: johkar | last post by:
I am confused on childNodes or children. When you have nested lists, I would think it would all be one list in the Dom, this doesn't seem to be the case. So how do you traverse an unordered list?...
4
by: Sergio Millich | last post by:
I have an annoyîng problem with a javascript tree. When you scroll down to the bottom of the tree and click to open a node the tree is refreshed and scrolls back to the top, hiding the node. Is...
0
by: Tree menu using XML | last post by:
I have one XML file that has nodes and sub node and each and every node has the attribute call visible if its value is true then diplay this node else don't display thid node, but this condition i...
4
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
1
by: Jesper DK | last post by:
Hi, I have docked a tree view to the left on a form. When I start to populate this tree view with nodes, a horizontal scroll box appears in the bottom of the tree view even though thee tree...
1
by: w.p. | last post by:
Hello! I have some trouble with my GUI. I have left panel with foldpanelbar, but i need one item but not collapsed - simple button. I split my left panel into two foldpanelbars with one button...
6
by: Travis | last post by:
Is there a community accepted best way to store a menu tree for an interface in a data structure. Ideally I would like something that searches fast so given a menu structure like this File / ...
3
by: Travis | last post by:
I've created a custom Tree template. The tree mimics a menu tree and has the following properties. - nodes are identified by a unique name - any node can have infinite child nodes - nodes are not...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.