Skip to content

Instantly share code, notes, and snippets.

@thure
Last active August 29, 2015 14:00
Show Gist options
  • Save thure/91b5cd743356a5cd3bb3 to your computer and use it in GitHub Desktop.
Save thure/91b5cd743356a5cd3bb3 to your computer and use it in GitHub Desktop.
An AMD module that gives a semantic string for the element that can be used in event dispatchers and/or switch statements.
define(function(){
return function(el){
var id = el.getAttribute('id');
if(id) {
return '#' + id;
}else if(typeof el.className === 'string' && el.className.length > 0){
var classes = el.className.hasOwnProperty('baseVal') ? el.className.baseVal.split(/ +/) : el.className.split(/ +/);
classes.unshift(el.tagName.toLowerCase());
return classes.join('.');
}else{
return el.tagName.toLowerCase();
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment