change class of element using js code example

Example 1: Javascript change element class

document.getElementById("myElementID").classList.add('myClassName');
document.getElementById("myElementID").classList.remove('myClassName');

Example 2: 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');
}