I am making use of matching a url from a tab to the window.location, but am using secure routes. How do I remove the a part of a string from a selected character, In my case the char is '?' I want to remove everything from the ? to the end of the string. How can this be done with jquery?
document.querySelectorAll('.nav-link').forEach(link => {
console.log(link);
if(link.href === window.location.href){
link.setAttribute('aria-current', 'page')
}
})
CodePudding user response:
you can use the split function simply like this
let link = link.split('?');
let required_link = link[0];
CodePudding user response:
document.querySelectorAll('.nav-link').forEach(link => {
if(link.pathname === window.location.pathname){
link.setAttribute('aria-current', 'page')
}
})