Skip to content

Instantly share code, notes, and snippets.

@teddykishi
Created July 14, 2014 13:38
Show Gist options
  • Save teddykishi/dfb4ddc8f2d8c89a8447 to your computer and use it in GitHub Desktop.
Save teddykishi/dfb4ddc8f2d8c89a8447 to your computer and use it in GitHub Desktop.
Get list of data attributes using with jQuery
(function($) {
$.fn.allData = function(){
var elements = [], data;
this.each(function(){
data = $(this).data();
elements.push(data);
});
return this.length === 1 ? elements[0] : elements;
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment