I'm pretty new to javascript and I'm trying to recreate this: https://ibb.co/hh45jH
new Box(0, 0, 20, 30, "#007", parentDiv)
doesn't produce anything at all and I'm not quite sure why. I want it to produce a colored div with the above specifications
This is my code so far:
class Box {
constructor(xPosition, yPosition, width, height, backgroundColor, parentElement) {
var div = document.createElement("div");
div.style.width = width;
div.style.height = height;
div.style.background = backgroundColor;
style.position = "absolute";
style.top = yPosition;
style.left = xPosition;
}
function draw() {
var parent = document.getElementById("parentDiv");
new Box(0, 0, 20, 30, "#007", parentDiv)
}
}
window.addEventListener("load", draw);
.parentDiv {
width: 500px;
height: 500px;
background-color: red;
}
<div class="parentDiv"></div>
I want the above JavaScript code to produce a new div with the given instructions (color, height, width and so on) and then place it in the parentDiv just like in the example (link above).
<>snippet editor and add code that shows the output and tell us the expected outputvar div = document.createElement("div"); var style = div.style;