js classlist hasclass code example
Example 1: js check for class in classList
element.classList.contains(className);
Example 2: query selector has clas
if (document.body.classList.contains('thatClass')) {
}
Example 3: query selector has clas
document.body.classList.add('thisClass');
document.body.classList.remove('thatClass');
document.body.classList.toggle('anotherClass');
Example 4: classlist
div.classList.remove("foo");
div.classList.add("anotherclass");
Example 5: classlist.contain in javascript
let span = document.querySelector("span");
let classes = span.classList;
let result = classes.contains("d");
if (result) {
span.textContent = "The classList contains 'c'";
} else {
span.textContent = "The classList does not contain 'c'";
}