skip to Main Content

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')
        }
    })

2

Answers


  1. Chosen as BEST ANSWER
    document.querySelectorAll('.nav-link').forEach(link => {
        if(link.pathname === window.location.pathname){
            link.setAttribute('aria-current', 'page')
        }
    })
    

  2. you can use the split function simply like this

    let link = link.split('?');
    let required_link = link[0];
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search