Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 1.96 KB  |  hits: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. List styling in JavaScript
  2. <ul id="navmenu">
  3.   <li><a href="#">Downloads &raquo;</a>
  4.     <ul>
  5.       <li><a href="downloads_flyer.php">Flyer</a></li>
  6.       <li><a href="downloads_jahresberichte.php">Jahresberichte</a></li>
  7.       <li><a href="downloads_banner.php">Banner</a></li>
  8.     </ul>
  9.   </li>
  10.   <li><a href="presse.php">Pressecenter</a></li>
  11.   <li><a href="kontakt.php">Kontakt</a></li>
  12. </ul>
  13.        
  14. var i = 0;
  15. var url = "<?php echo end(explode("/", $_SERVER["SCRIPT_NAME"])); ?>";
  16. var liste = document.getElementById("navmenu").getElementsByTagName("li");
  17. while(i < liste.length) {
  18.     var topList = liste[i];
  19.     var topLink = liste[i].getElementsByTagName("a")[0];
  20.     if (topLink.href.substr((topLink.href.length - 1), 1) != "#"  // To avoid matching the 'Downloads' link.
  21.      && topLink.href.indexOf(url) > 0)
  22.     {
  23.         topList.className = "active";
  24.     }
  25.     i++;
  26. }
  27.        
  28. var i = 0;
  29. var url = "<?php echo end(explode("/", $_SERVER["SCRIPT_NAME"])); ?>";
  30. var liste = document.getElementById("navmenu").getElementsByTagName("li");
  31. while(i < liste.length) {
  32.     var topLink = liste[i].getElementsByTagName("a")[0];
  33.     if (topLink.href.substr((topLink.href.length - 1), 1) != "#"  // To avoid matching the 'Downloads' link.
  34.      && topLink.href.indexOf(url) > 0)
  35.     {
  36.         if(topLink.parentNode.parentNode.parentNode.tagName == "LI") {
  37.             topLink.parentNode.parentNode.parentNode.className = "active";
  38.         } else {
  39.             topLink.parentNode.className = "active";
  40.         }
  41.     }
  42.  
  43.     i++;
  44. }
  45.        
  46. var i = 0;
  47. var url = "<?php echo end(explode("/", $_SERVER["SCRIPT_NAME"])); ?>";
  48. var liste = document.getElementById("navmenu").getElementsByTagName("li");
  49. while(i < liste.length) {
  50.     var topLink = liste[i].getElementsByTagName("a")[0];
  51.     if (topLink.href.substr((topLink.href.length - 1), 1) != "#"  // To avoid matching the 'Downloads' link.
  52.      && topLink.href.indexOf(url) > 0)
  53.     {
  54.         topLink.parentNode.parentNode.parentNode.className = "active";
  55.     }
  56.  
  57.     i++;
  58. }