adding attributes to createelement code example
Example: javascript create element with attributes
var element = document.createElement("span");
element.setAttribute("style", "color: red");
document.body.appendChild(element);
var element = document.createElement("span");
element.setAttribute("style", "color: red");
document.body.appendChild(element);