I'm having a problem adding an active class the my navigation <li>.
I'm trying to use jquery to add this class based on the dir level and
not the file name.  Reason being, each dir is going to have sub
directories and misc html files that will be linked together within
the main dir.

I was trying to use the script detailed in this tutorial:
http://www.cssnewbie.com/using-javascript-to-style-active-navigation-elements/
but it didn't work so well.

my original is only adding the class to the <li> based on the file
name.

function markActiveLink() {
        var currentURL = window.location.toString().split("/");
        var currentDIR = currentURL[currentURL.length-2];
        //alert(currentDIR);
$("#nav li a").filter(function() {
        return $(this).attr("href") == currentURL[currentURL.length-1];
        }).parent().addClass("current");

if($("#nav li").hasClass("current") == false) {
        //alert(currentDIR);
        $("#nav li:nth-child(2)").addClass("current");
    }
 }

markActiveLink();


my navigation is kinda like this:
<ul id="nav">
<li><a href="../index.html">Internal Home</a></li>
                    <li><a href="../members/">Members</a></li>
                    <li><a href="../committees/">Committees</a></li>
</ul>

any help is greatly appreciated!

thank you,
gerald

Reply via email to