how to add a class to html using javascript
snippet in javascript

how to add a class to html using javascript

user5688

function myFunction() {
  var element = document.getElementById("myDIV");
  element.classList.add("mystyle");
}

javascript add class to element

user8166

var someElement= document.getElementById("myElement");
    someElement.className += " newclass";//add "newclass" to element (space in front is important)