My links are like that:
index.php
index.php?do=that
index.php?do=this
And my current javascript code is like that:
var url = window.location.pathname,
urlRegExp = new RegExp(url.replace(/\/$/,'') + "$");
console.log(url);
$('.nav-link').each(function(){
if(urlRegExp.test(this.href.replace(/\/$/,''))){
$(this).addClass('active');
}
});
});
So with this code even if I'm at index.php?do=this
console log says to me /path/index.php
I think I need make changes on var url = window.location.pathname
line but I couldn't.
How should I improve my code? There are bunch of similiar questions here in SO, but not the same one.
I appreciate any help.