Created
October 29, 2014 17:26
-
-
Save daihuaye/b4493794201e97694e4c to your computer and use it in GitHub Desktop.
dataset is not worked in ie 9, pitfall
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
| var myElement = document.getElementById('myElement'), // contains attribute data-my-custom-value | |
| myCustomValue; | |
| if(myElement.dataset !== undefined) { // standard approach | |
| myCustomValue = myElement.dataset.myCustomValue; | |
| } else { | |
| myCustomValue = myElement.getAttribute('data-my-custom-value'); // IE approach | |
| myElement.setAttribute('data-my-custom-value', 'new value') // set new value on the data attribute | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment