Created
April 21, 2010 15:43
-
-
Save kylefox/373988 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
* Sweet sugar for jQuery's $.data API. | |
* http://yehudakatz.com/2009/04/20/evented-programming-with-jquery/ | |
* | |
* Instead of this: | |
* | |
* $("#foo").data("foo"); // Get foo | |
* $("#foo").data("foo", 'bar'); // Set foo | |
* | |
* Do this: | |
* | |
* $$('#foo').foo; // Get foo | |
* $$('#foo').foo = "bar"; // Set foo | |
* | |
*/ | |
var $$ = function(param) { | |
var node = $(param)[0]; | |
var id = $.data(node); | |
$.cache[id] = $.cache[id] || {}; | |
$.cache[id].node = node; | |
return $.cache[id]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment