Skip to content

Instantly share code, notes, and snippets.

@notmasteryet
Created December 16, 2011 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notmasteryet/1484177 to your computer and use it in GitHub Desktop.
Save notmasteryet/1484177 to your computer and use it in GitHub Desktop.
// HTMLElement dataset property
(function checkDatasetProperty() {
var div = document.createElement('div');
if ('dataset' in div)
return; // dataset property exists
Object.defineProperty(HTMLElement.prototype, 'dataset', {
get: function htmlElementDatasetGetter() {
// adding dataset field to the actual object
return (this.dataset = {});
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment