Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
17.2k views
in Web Development by 37 41 48
recategorized by

I need to get the query string value from the current URL using JQuery or Javascript,

For example, the current page URL is

http://mydomain/?id=1

the expected value should be 1, What's the best way to get query string value from URL in JQuery or Javascript without using custom function?


1 Answer

1 like 0 dislike
by 2 2 9
selected by
 
Best answer

How to get URL parameters Value in JavaScript?

The below code would help to get URL parameters Value from URL using JavaScript instead of JQuery:

var QueryString = (new URL(location.href)).searchParams.get('id');
if(QueryString) 
console.log(QueryString);
by 37 41 48
0 0
It's the simplest way I have ever seen, Thank you!
If you don’t ask, the answer is always NO!
...