Skip to content

Instantly share code, notes, and snippets.

@kylefox
Created April 21, 2010 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kylefox/373988 to your computer and use it in GitHub Desktop.
Save kylefox/373988 to your computer and use it in GitHub Desktop.
/*
* 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