After using JavaScript to generate some divs, I ended up with the following code:
const container = document.querySelector('#container');
for(let i = 1; i < 17; i++) {
var row = document.createElement('div');
row.id = 'r' + i;
row.class = 'row';
container.appendChild(row);
for(let j = 1; j < 17; j++) {
var newDiv = document.createElement('div');
newDiv.id = 'c' + j;
newDiv.class = 'box';
newDiv.textContent = row.id;
row.appendChild(newDiv);
}
}
Attempting to style the row divs by adding a green border using CSS:
#row {
border: 1px solid green;
}
Why are the rows not displaying with a green border? Can CSS target elements created dynamically in JavaScript?
I expected 16 boxes for each of the 16 div elements with class "row".