-4

I am developing an app and we required some dynamic data so i wanted to change parameter name using Jquery.

This is my URL which has only 1 parameter:
http://localhost:8888/games/result?subcat=lisconbyc&mode=16

is it possible to change parameter name "mode" to "release"

so after changing the parameter name it should become
http://localhost:8888/games/result?subcat=lisconbyc&release=16

Please help.

3
  • 2
    Why on earth would you insist on using jQuery to do this? jQuery doesn't have any features that help with this kind of operation. Commented Jan 6, 2021 at 11:29
  • @Quentin plain JS? Commented Jan 6, 2021 at 11:30
  • 2
    Does this answer your question? How can I add or update a query string parameter? Commented Jan 6, 2021 at 11:31

1 Answer 1

0

This can be done with plain old JavaScript:

console.log("http://localhost:8888/games/result?subcat=lisconbyc&mode=16".replace("&mode=","&release="))

So, in case there are multiple <a> elements on your page you can carry out this change with jQuery (if you wish) in the following way:

$("a").each(function(){this.href=this.href.replace("&mode=","&release=")});
Sign up to request clarification or add additional context in comments.

1 Comment

works good, but i am trying something like this but doesn't work changeurl = (thisdata.replace("&mode=","&release=")); $(this).find('.nopres').attr('href', $(e.relatedTarget).changeurl);

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.