jquery active class to menu item based on current url

jquery

Solution

Try this:

$("#accordion a").each(function() {   
    if (this.href == window.location.href) {
        $(this).addClass("active-sidebar-link");
    }
});

Problem

I have the following code that should add an active css class to the menu item if menu item url == current url: ``` $("#accordion a").each(function() { if (this.href.search(window.location.hostname) != -1) { $(this).addClass("active-sidebar-link"); } }); ``` but this adds the class to all the menu items. any tips?

Original source