-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.

  • 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. – Quentin Jan 06 '21 at 11:29
  • @Quentin plain JS? – Waleedviews Jan 06 '21 at 11:30
  • 2
    Does this answer your question? [How can I add or update a query string parameter?](https://stackoverflow.com/questions/5999118/how-can-i-add-or-update-a-query-string-parameter) – N.J.Dawson Jan 06 '21 at 11:31

1 Answers1

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=")});
Carsten Massmann
  • 16,701
  • 2
  • 16
  • 39