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");
});
});
You can play with window.location which will return the current page URL and also the href property of the window.location
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With