Created
April 10, 2014 01:15
-
-
Save veltman/10335088 to your computer and use it in GitHub Desktop.
jQuery cacher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Return a cached selection if it's been used, | |
//Otherwise get the jQuery selection and cache it | |
var $$ = function(x) { | |
if (!this[x]) this[x] = $(x); | |
return this[x]; | |
}; | |
//Use $ where the selection results might change between selections | |
$("div.whatever").show(); //Get a new selection | |
$("div.whatever").hide(); //Get a new selection | |
//Use $$ where they won't | |
$$("div.whatever").show(); //Get a new selection the first time | |
$$("div.whatever").hide(); //Get it from cache |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment