This feels like a beginner question with a pretty obvious answer, but I can’t figure it out for the life of me. What is the problem with my attempt below to create a new element and add it to the body?
var newDiv = document.createElement("div");
newDiv.setAttribute("id", "popup");
newDiv.setAttribute("width", "400px");
newDiv.setAttribute("height", "400px");
newDiv.setAttribute("backgroundColor", "red");
document.getElementsByTagName("body")[0].appendChild(newDiv);
newDiv.style.position = "absolute";
newDiv.style.left = "25px";
newDiv.style.top = "25px";
Width and height attributes won’t work with “px” in them and I am not sure about the background attribute either. Either way, the following does work and is the way you should do it: