Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.