Jump to content

Archived

This topic is now archived and is closed to further replies.

Qazsad

Newbie's Creating Menu with Javascript Tree neeeedsss Help

Recommended Posts

Hello Guys
Do you have sample codes for creating javascript Tree. Coz i would like to create a menu on my page
and hiding its submenu first. The Submenu's will only be shown if The Mainmenu will be clicked and other submenus from other will be hidden if they are not part of the current mainmenu.
Say

Selecting MainMenu2:

MainMenu1
MainMenu2
MM2_SubMenu1
MM2_SubMenu2
MainMenu3

Selecting MainMenu1:

MainMenu1
MM1_SubMenu1
MM1_SubMenu2
MainMenu2
MainMenu3


Share this post


Link to post
Share on other sites
try this
[code]
<script language="javascript">
function hide(){
     var sub_menus_array = new Array("sub1","sub2","sub3");  // sub menu ids
     for(i=0; i<sub_menus_array.length; i++){
          document.getElementById(sub_menus_array[i]).style.display = "none";
     }
}
function show(sub_menu){
     hide();
     document.getElementById(sub_menus_array[i]).style.display = "block";
}
<script>

<a href="#" onClick="show('sub1');">MainMenu1</a>
<div id="sub1" style="display:none;">
MM1_SubMenu1
MM1_SubMenu2
</div>
<a href="#" onClick="show('sub2');">MainMenu2</a>
<div id="sub2" style="display:none;">
MM2_SubMenu1
MM2_SubMenu2
</div>
<a href="#" onClick="show('sub3');">MainMenu3</a>
<div id="sub3" style="display:none;">
MM3_SubMenu1
MM3_SubMenu2
</div>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.