Created
September 23, 2019 10:12
-
-
Save sahava/a2dc60f0cbb75b65906d04f0f088eb7c to your computer and use it in GitHub Desktop.
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
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