Answers for "classlist has class javascript"

5

js check for class in classList

element.classList.contains(className);
Posted by: Guest on August-27-2020
1

if classlist contains js

element.classList.contains(class);
Posted by: Guest on December-10-2020
2

add to classlist javascript

Add multiple classes to a <div> element:
document.getElementById("myDIV").classList.add("mystyle", "anotherClass", "thirdClass");

Remove a class from a <div> element:
document.getElementById("myDIV").classList.remove("mystyle");

Remove multiple classes from a <div> element:
document.getElementById("myDIV").classList.remove("mystyle", "anotherClass", "thirdClass");

Toggle between two classes for a <div> element:
document.getElementById("myDIV").classList.toggle("newClassName");

Find out if an element has a "mystyle" class:
document.getElementById("myDIV").classList.contains("mystyle");
Posted by: Guest on June-29-2020
0

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'";
}
Posted by: Guest on February-06-2021
0

.classList

// .classList method returns an array of the classes attached to the element it is called with.
document.getElementById("myDIV").classList
// It returns
// [ 'className1', 'className2', ... ]
Posted by: Guest on April-26-2020

Code answers related to "classlist has class javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language