Coding⏱️ 2 min read📅 2026-06-03

How to Fix: How can I add or update a query string parameter?

Update query string parameter using jQuery

Quick Answer: Use the $.param() function to update or add a query string parameter: $.param({ paramName: 'newValue' });

To add or update a query string parameter using JavaScript and jQuery, you can utilize the URLSearchParams API. This API provides an easy way to work with URL query strings.

How to Add or Update a Query String Parameter

  • Use the URLSearchParams API to parse the current query string.

Method 1: Adding a New Parameter

  1. Step 1: Get the current URL.
  2. Step 2: Parse the query string using URLSearchParams.
  3. Step 3: Add the new parameter to the parsed query string.
  4. Step 4: Construct a new URL with the updated query string.

Method 2: Updating an Existing Parameter

  1. Step 1: Get the current URL.
  2. Step 2: Parse the query string using URLSearchParams.
  3. Step 3: Update the existing parameter in the parsed query string.
  4. Step 4: Construct a new URL with the updated query string.

✅ Example Code

const url = 'https://example.com/path?a=1&b=2';
} const params = new URLSearchParams(url.split('?')[1]);
params.set('c', 3);
const updatedUrl = `https://example.com/path?${params.toString()}`;

✨ Wrapping Up

By utilizing the URLSearchParams API, you can easily add or update query string parameters in your JavaScript applications using jQuery.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions