Apu
December 15, 2022 ›
#dynamically
›
#HowTo
❌
How to add a parameter to the URL using JavaScript
In this article, you will see how we can dynamically add a parameter to a URL in JavaScript.
So we have the following URL and we want to add a parameter to that URL.

To add a parameter to the URL, we are going to use :
URL.searchParams : the searchParams readonly property of the URL interface returns a URLSearchParams object.
Element.append() : the append() method inserts a set of Node objects or string objects after the last child of an element.
<button onclick="myFunc()">Add Parameter</button>
<div id="my-div"> </div>
<script>
let url = new URL("https://www.3schools.in");
const myDiv = document.getElementById('my-div');
function myFunc() {
url.searchParams.append('parameter', 'value');
myDiv.innerHTML = url;
}
</script>
save
listen
AI Answer
How to add a parameter to the URL using JavaScript
0
In this article, you will see how we can dynamically add a parameter to a URL in JavaScri…
asked
Apu
0 answers
2915
In this article, you will see how we can dynamically add a parameter to a URL in JavaScri…
Answer Link
answered
Apu
