tags:

views:

46

answers:

1

I have a dynamically created UL. I want to use jQuery to use the current URL, search through a specified UL and find any li with a matching href. If one is found then add the class "current_page".

I came up with this but it doesn't seem to do the trick.

$(document).ready(function() {  
    $("ul.nav_cat_archiveli").find("a[href='"+window.location.pathname+"']").each(function() {
        $(this).addClass("current_page");
    });
});
+1  A: 

You can play with window.location which will return the current page URL and also the href property of the window.location

Amr ElGarhy
Excellent! Got to be the quickest answer ever! I changed the .pathname to .href and it works exactly as required. Thank you.
Dan