Skip to content

Instantly share code, notes, and snippets.

@sahava
Created September 23, 2019 10:12
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 sahava/a2dc60f0cbb75b65906d04f0f088eb7c to your computer and use it in GitHub Desktop.
Save sahava/a2dc60f0cbb75b65906d04f0f088eb7c to your computer and use it in GitHub Desktop.
function() {
// Update this array with the class names
var classes = ['class1', 'class2', 'class3'];
// Fetch elements
var els = document.querySelectorAll('.' + classes.join(',.'))
return [].map.call(els, function(e) {
// Get first matching class name per element
return classes.filter(function(c) {
return e.className.indexOf(c) > -1;
}).shift();
}).filter(function(v,i,s) {
// Remove duplicates
return s.indexOf(v) === i;
}).sort(function(a, b) {
// Sort in alphabetical order
if (a > b) return 1;
if (a < b) return -1;
return 0;
}).join();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment