user5088521
0
Q:

how to add a class to html using javascript

function myFunction() {
  var element = document.getElementById("myDIV");
  element.classList.add("mystyle");
}
8
var someElement= document.getElementById("myElement");
    someElement.className += " newclass";//add "newclass" to element (space in front is important)
27

New to Communities?

Join the community