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

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -