How to replace or remove specific string from url in jquery.
Replacing some specific string from url is somewhat tricky job we need to do in our day to day life in IT field for making something dynamic.
Here is the working solution you can try given below.
const urlParams = new URLSearchParams(window.location.search); // need this for search in url var param = ""; // declared param variable var dynamicHref = window.location.href; // dynamic link of current url param_x = urlParams.get("string=55,22"); // find string from url param_x = param_x.split(',').join('%2C'); // replace comma with (& or %2C) param_x = dynamicHref.replace("string=" + param_x, ""); // replace string with null $(".custom-href-class").attr("href", param_x); // you can now put dynamic link to anchor tag.
Above given solution is tried and found working. If you are stuck somewhere then feel free to comment down. Hopefully i try to gives you the solution.