I'm trying to figure out how to write an if statement that works something like this:
if (element contains class 1 && class 2) {
// do this
}
How do I write that if statement to check for multiple classes?
Is there a way to make the .contains method check for more than one class?
What I've found so far:
How to check class of multiple class elements in javascript, without jquery
Problem is, it seems to be returning an array of all the classes that the element contains, which is not what I want. I need the function to check if the element contains the classes that I am supplying it with.
One of the solutions looks to me like it's asking us to create our own function to do this, but is there a native method on JS which will do the trick?
I'm quite new to this stuff and I really appreciate the patience you guys have shown in answering my questions.
matchesis the answer, if element.classList returns all the classes of an element, how hard is it to compare it to a list of classes you are supplying? it's programming 101.