Home  >  Article  >  Web Front-end  >  Javascript method to show and hide ul list_javascript tips

Javascript method to show and hide ul list_javascript tips

WBOY
WBOYOriginal
2016-05-16 15:50:182135browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn