How to change css for active link based on the hashtag

前端 未结 2 666
轻奢々
轻奢々 2021-01-22 02:37

I have a situation here on how to change my active link css based on the hashtag. All the content was in the same page and I use the #url section to call the content.

i

2条回答
  •  情歌与酒
    2021-01-22 03:33

        jQuery(function() {
          jQuery('a').each(function() {
            if (jQuery(this).attr('href')  ===  window.location.href) {
              jQuery(this).addClass('active');
            }
          });
        });  
    
    .active {
        color: #BBA842!important;
    }
    

提交回复
热议问题