171
rated 0 times
[
176]
[
5]
/ answers: 1 / hits: 25428
/ 10 Years ago, fri, december 19, 2014, 12:00:00
I needed to use element.classList.contains('some-class')
to check if an element contains at least one of three classes, so I wrote:
if (element.classList.contains('class1', 'class2', 'class3')) {
// do stuff here
}
The result was - if the element has 'class1', it returns true, no matter if it has 'class2' or/and 'class3', and
// do stuff here
executes. However, if it has 'class2' and/or 'class3', it returns false and
// do stuff here
does not execute.
I worked around it with:
if (element.classList.contains('class1') || element.classList.contains('class2') || element.classList.contains('class3')) {
// do stuff here
}
More From » javascript