Skip to content

Instantly share code, notes, and snippets.

@tsvensen
tsvensen / getQueryParameters
Last active August 29, 2015 13:56
Get Query Params
// Plugin to get query params as an object
jQuery.extend({
getQueryParameters : function(str) {
return (str || document.location.search).replace(/(^\?)/,'').split("&").map(function(n){return n = n.split("="),this[n[0]] = n[1],this}.bind({}))[0];
}
});
// EXAMPLE
// http://codepen.io/chriscoyier/pen/uszCr?lunch=sandwich&dinner=stirfry
var queryParams = $.getQueryParameters();
@tsvensen
tsvensen / gist:4efedfe486ecbc4d3345
Created September 5, 2014 22:02
jQuery Element Caching System
// Requires underscore or lodash for isUndefined()
var $cache = {};
/**
* Returns the page title element and will set the page title element when it doesn't exist
* @param {String} selector
* @returns {jQuery}
*/
getElement: function getElement(selector) {
if (typeof selector !== 'string') {