Answers for "javascript how to change class name"

8

change elements class javascript

document.getElementById("MyElement").classList.add('MyClass');

document.getElementById("MyElement").classList.remove('MyClass');

if ( document.getElementById("MyElement").classList.contains('MyClass') )
{
document.getElementById("MyElement").classList.toggle('MyClass');
}
Posted by: Guest on July-06-2020
12

javascript change element class

//Overwrite all classes
element.className = "class";

//Add class
element.classList.add("class");
Posted by: Guest on June-02-2020

Code answers related to "javascript how to change class name"

Code answers related to "Javascript"

Browse Popular Code Answers by Language