css class javascript code example
Example 1: javascript add class to element
var someElement= document.getElementById("myElement");
someElement.className += " newclass";
Example 2: element.classname javascript
let el = document.getElementById('item');
if (el.className === 'active'){
el.className = 'inactive';
} else {
el.className = 'active';
}
Example 3: js css class
const element = document.getElementById("myDIV");
element.classList.add("myClass");
const element = document.getElementById("myDIV");
let classList = element.classList;