How to match URL with href in jQuery?

后端 未结 3 644
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-26 06:05

Using a list for navigation, I am looking for a clean way to apply the \'selected\' class to a list item if the page URL (minus anything after the path) matches the href of the

3条回答
  •  情话喂你
    2021-01-26 06:39

    Assuming there isn't any '?' character in the actual path you could use something like this for both the location and the href:

    function getBaseURL(url) {
        return url.split('?')[0];
    }
    

提交回复
热议问题