js classlist has class code example

Example 1: js check for class in classList

element.classList.contains(className);

Example 2: if classlist contains js

element.classList.contains(class);

Example 3: classList has class

if (document.body.classList.contains('thatClass')) {
    // do some stuff
}

Example 4: 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'";
}