Get Values from Data Attribute
This file contains 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
// 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