Skip to content

Instantly share code, notes, and snippets.

@LiamChapman
Last active January 1, 2016 23:59
Show Gist options
  • Select an option

  • Save LiamChapman/8219867 to your computer and use it in GitHub Desktop.

Select an option

Save LiamChapman/8219867 to your computer and use it in GitHub Desktop.
Shorthand for natively getting and setting data attributes
Element.prototype.data = function(attr, value) {
var attr = 'data-'+attr;
if (value) {
return this.setAttribute(attr, value);
} else {
return this.getAttribute(attr)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment