I have the following elements:
How do I check if any of these elements has one of the classes in the array
You'd have to iterate over elements and classes, and check if each element contain any of the classes in the array, something like this
var elements = $('div');
var obj = ['nine', 'ten', 'eleven'];
var hasClass = elements.filter(function(index, elem) {
return obj.some(function(klass) {
return elem.classList.contains(klass);
});
}).length > 0;
You could easily make that into a function
function hasClass(elements, classes) {
return elements.filter(function(index, elem) {
return classes.some(function(klass) {
return elem.classList.contains(klass);
});
}).length > 0;
}
FIDDLE
Using Array.some
and Element.classList.contains
to avoid uneccessary iteration and slow matching of classnames.