Skip to content

Instantly share code, notes, and snippets.

@mcmullengreg
Created September 29, 2016 16:36
Show Gist options
  • Save mcmullengreg/0b0d869c407d1f8cd6d528f4ae786054 to your computer and use it in GitHub Desktop.
Save mcmullengreg/0b0d869c407d1f8cd6d528f4ae786054 to your computer and use it in GitHub Desktop.
function() {
var isSet = function(val) {
return val !== null && val !== '';
};
var el = {{element}};
var val = ( isSet(el.getAttribute('data-label')) ? el.getAttribute('data-label') : el.text );
while (el && el !== document.body && !isSet(val)) {
el = el.parentElement;
val = el.getAttribute('data-label');
}
return isSet(val) ? val : 'not set';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment