Skip to content

Instantly share code, notes, and snippets.

@daihuaye
Created October 29, 2014 17:26
Show Gist options
  • Select an option

  • Save daihuaye/b4493794201e97694e4c to your computer and use it in GitHub Desktop.

Select an option

Save daihuaye/b4493794201e97694e4c to your computer and use it in GitHub Desktop.
dataset is not worked in ie 9, pitfall
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