how to create a dom class js code example

Example 1: create element javascript with class

// create div element by javascript with class

var div = document.createElement('div');
div.className = "div1";

Example 2: Javascript change element class

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

Example 3: js create element with class

var element =document.createElement("span");
        element.className = "aClassName";