Created
October 21, 2013 18:34
-
-
Save marcusgadbem/7088678 to your computer and use it in GitHub Desktop.
jQuery/Zepto DOM Caching
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
$C = (function($) { | |
var DOMCACHESTORE = {}; | |
return function(selector, force) { | |
if (DOMCACHESTORE[selector] === undefined || force) | |
DOMCACHESTORE[selector] = $(selector); | |
return DOMCACHESTORE[selector]; | |
} | |
})($); | |
// usage: | |
$C('h1').hide().fadeIn('slow'); | |
$C('a').click(function(e){ alert('link clicked'); }); | |
// refresh item in cache | |
$C('h1', true).hide().fadeIn('slow'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment