63
rated 0 times
[
70]
[
7]
/ answers: 1 / hits: 15586
/ 13 Years ago, fri, june 17, 2011, 12:00:00
In my HTML, I have a div
like so:
<div class=a b c></div>
In my JavaScript, I have an array of classes that I'm interested in:
var goodClasses = ['a', 'c'];
In good browsers, I can use the awesome classList
feature to test whether or not my div
has the appropriate classes:
return div.classList.contains(goodClasses[0], goodClasses[1]);
This is okay, but what I'd really like to do is something like this (the syntax is silly, but this is the general idea):
return div.classList.contains.apply(div, goodClasses);
Is there some way to do this? If I have to loop through my array of classes anyway, classList
becomes a whole lot less cool.
More From » javascript