Jump to content

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


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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.