How do you inject this code into HTML using Javascript?

var div = document.createElement("div");
div.setAttribute("id", "bar");
div.style.position = "fixed";
div.style.top = "0";
div.style.left = "0";
div.style.height = "50px";
div.style.width = "50px";
div.style.backgroundColor = "#ccc";

document.body.appendChild(div);

Leave a Comment