const parentDiv = document.querySelector(".parent-div");
for (var i = 0; i < 10; i++) {
var childDiv = document.createElement("div");
childDiv.style.display = "flex";
childDiv.style.flex = "1";
for (var k = 0; k < 10; k++) {
var newChild = document.createElement("div");
newChild.style.flex = "1";
newChild.style.height = "48px";
newChild.style.width = "48px";
newChild.style.border = "2px black solid";
newChild.style.color = "#f389ca";
newChild.addEventListener("mouseover", function(){
newChild.style.color = "#8e2db8";
});
newChild.addEventListener("mouseout", function(){
newChild.style.color = "#f389ca";
});
childDiv.appendChild(newChild);
}
parentDiv.appendChild(childDiv);
}
i want to dynamically create a row of square divs, then multiple such rows and add them to the parent-div already in the HTML file.
edit: script was loading before the parent-div element, hence it wasn't creating any squares in it
solution: either load the js file at the end of body or use
edit2: use CSS: background-color instead of color