Answers for "give an element a class javascript"

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
1

javascript give class to element

element.classList.add("div-class");
Posted by: Guest on February-01-2021

Code answers related to "give an element a class javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language