Add “.active” class to the current page’s link in a menu using jQuery or PHP [closed]

You can use jQuery to loop through all links and compare their URLs with location. Here is an example:

$(".sf-menu a").filter(function(){
    return this.href == location.href.replace(/#.*/, "");
}).addClass("active");

Leave a Comment