javascript - str.replace not functioning as expected -


i writing function check if url param in url. if there removing , if not yet there adding it. toggling param on button click. here have far.

     var value1 = $(this).attr("value");      var collectionurl = window.location.href;        if (collectionurl.includes($(this).attr("value")))  {           console.log("removing:   "  + $(this).attr("value"));           collectionurl.replace(value1,"");       }       else {           console.log("adding:   "  + $(this).attr("value"));           collectionurl = collectionurl + $(this).attr("value")+"/";         }     ajaxloadpage(collectionurl); 

when value absent value added the url expected. when value present in url, if statement work , outputs "removing: " value

however value in url not being removed. feel missing something.

calling "abc".replace("b","d") not change "abc" returns new string "adc" need store result in collectionurl.

so call collectionurl = collectionurl.replace(value1,"");


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -