js classList code example
Example 1: add multiple class list at once in js
elem.classList.add("first");
elem.classList.add("second");
elem.classList.add("third");
is equal to :
elem.classList.add("first","second","third");
Example 2: js classlist
classList.item(index);
classList.contains(token);
classList.add(token1[, ...tokenN]);
classList.remove(token1[, ...tokenN]);
classList.replace(oldToken, newToken);
classList.supports(token);
classList.toggle(token[, force]);
classList.entries();
classList.forEach(callback[ ,thisArg]);
classList.keys();
classList.values();
Example 3: css class list
var myElement = document.getElementById("myElementID");
myElement.classList.add("style1 style2");
myElement.classList.remove("style1 style2");
Example 4: classList has class
if (document.body.classList.contains('thatClass')) {
}
Example 5: class list contains class java
List<Card> hand = ...;
for(Card card : hand){
if (card instanceof AceOfDiamonds) return true;
}
Example 6: classlist
div.classList.remove("foo");
div.classList.add("anotherclass");