Last active
January 1, 2016 23:59
-
-
Save LiamChapman/8219867 to your computer and use it in GitHub Desktop.
Shorthand for natively getting and setting data attributes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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