Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How javascript hides drop-down menus

Shulou Source: shulou.com Published: 2022-05-31 10:37:38 11月24日 Update

This article mainly introduces the relevant knowledge of "javascript how to hide the drop-down menu", the editor shows you the operation process through the actual case, the operation method is simple and fast, practical, I hope this "javascript how to hide the drop-down menu" article can help you solve the problem.

Javascript hides the drop-down menu by first creating a "demo.html" and "demo.css", then creating a "demo.js", and finally hiding it through "function hideSubMenu (li) {...}".

This article operating environment: windows7 system, javascript1.8.5 version, Dell G3 computer.

How does javascript hide drop-down menus?

Javascript realizes the display and hiding of drop-down menus

Demo.html

Realize the drop-down menu effect on the home page of the course hall JavaScript Html/CSS learning center video learning examples question and answer A classic case about us.

Demo.js

Function displaySubMenu (li) {var subMenu = li.getElementsByTagName ("ul") [0]; subMenu.style.display = "block";} function hideSubMenu (li) {var subMenu = li.getElementsByTagName ("ul") [0]; subMenu.style.display = "none";}

Demo.css

* {margin:0px; padding:0px;} body {font-family:Verdana, Geneva, sans-serif; font-size:14px;} # nav {width:600px; height:40px; background-color:#eee; margin:0 auto;} ul {list-style:none;} ul li {float:left; line-height:40px; text-align:center; width:100px;} a {text-decoration:none; color:#000; display:block;} a:hover {color:#F00; background-color:#666 } ul li ul li {float:none;background-color:#eee; margin:2px 0px;} ul li ul {display:none;}

Effect:

That's all for "how javascript hides the drop-down menu". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Menus drop-down knowledge effects methods cases industries learning different practical content halls learning centers examples practicality practical articles more environment computer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple NVidia Redmi Shulou Tech Info Shulou Technology