I want to find all the href containing current url even if the whole href is longer. E.g.
Current url:www.example.com/portfolio/
a href url: www.example.com/portfolio/#28
What I want to do is to add class to all <a>'s containing current url path (even if they are longer). 
I used something like this: 
<script type="text/javascript">
var nav = $(location).attr('href');
if (nav) { 
jQu开发者_如何学编程ery('a[href$="' + nav + '"]').parent().addClass('current');
}
</script>   
But the code add the class only to 's containg the exact same path like current url.
Use the starts with selector:
<script type="text/javascript">
var nav = $(location).attr('href');
if (nav) { 
jQuery('a[href^="' + nav + '"]').parent().addClass('current');
}
</script> 
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论