Need Help With CSS menu to make the class active for the given nested menu...

Discussion in 'JavaScript' started by rohansyco, Nov 7, 2010.

  1. #1
    Hi,

    I m using a CSS menu which is as follows::
    <div id="topnav">
    <ul>
    <li><a href="index.html">Home</a>
    <ul>
    <li><a href="#">Libero</a></li>
    <li><a href="#">Maecenas</a></li>
    <li><a href="#">Mauris</a></li>
    <li class="last"><a href="#">Suspendisse</a></li>
    </ul>
    </li>
    <li><a href="style-demo.html">Style Demo</a>
    <ul>
    <li><a href="#">Lorem ipsum dolor</a></li>
    <li><a href="#">Suspendisse in neque</a></li>
    <li class="last"><a href="#">Praesent et eros</a></li>
    </ul>
    </li>
    <li><a href="full-width.html">Full Width</a>
    <ul>
    <li><a href="#">Lorem ipsum dolor</a></li>
    <li><a href="#">Suspendisse in neque</a></li>
    <li class="last"><a href="#">Praesent et eros</a></li>
    </ul>
    </li>
    <li><a href="#">Our Services</a></li>
    <li class="last"><a href="#">Long Link Text</a></li>
    </ul>
    </div>
    </div>

    i m using this menu in asp.net

    and to show that the preset link is active the CssClass of the link have to be "Active"

    so i use the following java script:

    <script type="text/javascript">
    window.onload = function() {
    var mnuLinks = document.getElementById("topnav").getElementsByTagName("a");
    for (i=0;i<mnuLinks.length;i++) {
    if(window.location.href.toLowerCase().search(mnuLinks.href.toLowerCase()) > -1) mnuLinks.className = "active";
    }
    }
    </script>


    but it is not working ...

    Please help me......

    Rohan....
     
    rohansyco, Nov 7, 2010 IP
  2. philst18

    philst18 Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try setAttribute("className","active")
     
    philst18, Nov 10, 2010 IP