Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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