Skip to content

Instantly share code, notes, and snippets.

@paulmkoch
Created September 11, 2014 22:16
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 paulmkoch/abcb72b12b9353fdb638 to your computer and use it in GitHub Desktop.
Save paulmkoch/abcb72b12b9353fdb638 to your computer and use it in GitHub Desktop.
Get Values from Data Attribute
// Returns: Values of data attribute
// Replace 'data-track-gtm' with the data attribute you're seeking
function() {
var isSet = function(val) {
return val !== null && val !== '';
};
var el = {{element}};
var val = el.getAttribute('data-track-gtm');
while (el && el !== document.body && !isSet(val)) {
el = el.parentElement;
val = el.getAttribute('data-track-gtm');
}
return isSet(val) ? val : false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment