Skip to content

Instantly share code, notes, and snippets.

@dankempster
Created June 28, 2011 10:33
Show Gist options
  • Save dankempster/1050870 to your computer and use it in GitHub Desktop.
Save dankempster/1050870 to your computer and use it in GitHub Desktop.
Get Query String value with jQuery
/**
* Sourced from http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript#answer-3855394
* @author BrunoLM <brunolm at codingwise dot com>
*/
(function($) {
$.queryString = (function(a) {
if (a == "") return {};
var b = {};
for (var i = 0; i < a.length; ++i)
{
var p=a[i].split('=');
if (p.length != 2) continue;
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
}
return b;
})(window.location.search.substr(1).split('&'))
})(jQuery);
// Usage:
$.queryString["param"];
@sindresorhus
Copy link

You shouldn't use jQuery for this.

Here's a plain JS module:
https://github.com/sindresorhus/query-string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment