Skip to content

Instantly share code, notes, and snippets.

@drinks
Created October 28, 2011 14:51
Show Gist options
  • Save drinks/1322457 to your computer and use it in GitHub Desktop.
Save drinks/1322457 to your computer and use it in GitHub Desktop.
jQuery deparam
/**
* jQuery.deparam
* reverses jQuery's param() method, converting a querystring back to an object
*/
(function($){
$.deparam = function(qs) {
var params, pieces;
params = {};
if (!qs) {
return params;
}
pieces = qs.split(/[&=]/);
$.each(pieces, function(idx, val) {
if (idx % 2) {
return params[pieces[idx - 1]] = val;
}
});
return params;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment