Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

Creating expandable and collapsible menu list with JavaScript

Posted on May 2, 2017August 4, 2020 by Habibie

Here is JavaScript & HTML source code to show you how to make expandable and collapsible menu list.

<!DOCTYPE html>
<html>
<head>
<title>Expand and Collapse Menu</title>
 <style>
    #menuTop, #menuTop ul{
		cursor:default;
		list-style-type:circle
	}
    #menuTop .m{
		list-style-type:disc
	}
    #menuTop ul{
		display:none
	}
  </style>

  <script>
   function showHide(ev){
     ev=ev||window.event
     var elem=(ev.target||ev.srcElement).getElementsByTagName("UL")[0]
     if(!elem)return;
     elem=elem.style;
     elem.display=(elem.display!='block')?'block':'none'
   }
  </script>
  
 </head>
 <body>
   <ul onclick="showHide(event)" id="menuTop">
    <li>Tutorial</li>
    <li class="m">Menu 1
      <ul>
      <li class="m">JavaScript
        <ul>
        <li class="m">Tutorial JavaScript
        <ul>
          <li>JavaScript for Beginner</li>
          <li>Intermediate JavaScript</li>
        </ul>
        </li>
        </ul>
      </li>
      <li>Java</li>
      </ul>
    </li>
    <li class="m">Menu 2
      <ul>
      <li class="m">Another Menu
        <ul>
        <li>Sub Menu 1</li>
        <li>Sub Menu 2</li>
        <li>Sub Menu 3</li>
        </ul>
      </li>
      </ul>
    </li>
    <li>Donate!</li>
 </ul>
 </body>
</html>

Here is the live result:

Post Views: 327
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Hover Reveal script for Unity to show and hide object on mouse hover
  • How to Prevent UI Clicks in Unity from “Bleeding Through” to 3D Objects Behind Them
  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
© 2026 ThirteeNov | Powered by Superbs Personal Blog theme