Home > Article > Web Front-end > Javascript method to show and hide ul list_javascript tips
The example in this article describes how to display and hide the ul list in Javascript. Share it with everyone for your reference. The details are as follows:
<ul id="rightNav"> <li> <h2 class="rightNavItem"><a href="#">Show & Hide</a></h2> <ul> <li><a href="">Links etc here</a></li> </ul> </li> </ul> <script> function enableRightNavExpand() { if (!document.getElementById) return false; if (!document.getElementById("rightNav")) return false; var nav = document.getElementById("rightNav"); var navItem = nav.getElementsByTagName("li"); for (var i = 0; i < navItem.length; i++){ navItem[i].onclick=function() { if (this.className == "selected") { this.className = ""; } else if (this.className == ""){ this.className = "selected"; } } } } </script>
I hope this article will be helpful to everyone’s JavaScript programming design.