Show / Hide an unordered list


/ Published in: JavaScript
Save to your folder(s)

This script allows you to show and hide a at the click of a button. See Show / Hide HTML for Markup.


Copy this code and paste it in your HTML
  1. function enableRightNavExpand() {
  2. if (!document.getElementById) return false;
  3. if (!document.getElementById("rightNav")) return false;
  4. var nav = document.getElementById("rightNav");
  5. var navItem = nav.getElementsByTagName("li");
  6. for (var i = 0; i < navItem.length; i++){
  7. navItem[i].onclick=function() {
  8. if (this.className == "selected") {
  9. this.className = "";
  10. }
  11. else if (this.className == ""){
  12. this.className = "selected";
  13. }
  14. }
  15. }
  16. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.