Skip to content

Instantly share code, notes, and snippets.

@hdragomir
Created December 15, 2010 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hdragomir/741786 to your computer and use it in GitHub Desktop.
Save hdragomir/741786 to your computer and use it in GitHub Desktop.
Quick jQuery plugin to parse data from an element and store it on the element via jQuery.data
(function($){
$.fn.parseData = function(){
return $(this).filter('[js-data]').each(function(){
var data = jQuery.parseJSON($(this).attr('js-data')), prop;
for(prop in data)
$(this).data(prop, data[prop]);
}).end();
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment