Created
September 28, 2016 05:33
-
-
Save joshuacerbito/84440729ef4a89dfb88b9eff78c509a4 to your computer and use it in GitHub Desktop.
IE-compatible data attribute getter/setter
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
Object.prototype.data = function (prop, val) { | |
var _return, | |
notIE = ( this.dataset !== undefined ); | |
return ( notIE )? // not IE | |
( typeof val === "undefined" ) ? // get data value | |
this.dataset[prop] : this.dataset[prop] = val | |
: // is IE | |
( typeof val === "undefined" ) ? // get data value | |
this.getAttribute('data-' + prop) : this.setAttribute('data-' + prop, val); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment