This successfully generate divs with and array name address as the id for example:
<div id="div1[0]" style="border: 1px solid rgb(0, 255, 0);"></div>
How then does on get a handle on that id using getElementById() examples below do not work. Either by directly access in the div if through the parent which is used in the constructor which is the array divArray();
var divArray = new Array(); // div array "holder"
var dCount = 0; // div array counter
class dyDiv {
constructor (){
var parentDiv = document.getElementById('canvas');
var div1 = document.createElement('div');
var div2 = document.createElement('div');
div1.setAttribute("id", "div1["+dCount+"]"); // id="div1[0]" id="div1[2]" ... and so on
div2.setAttribute("id", "div2["+dCount+"]");
div1.style.border = "1px #f00 solid"; // red border
div2.style.border = "1px #0f0 solid"; // green border
parentDiv.appendChild(div1);
parentDiv.appendChild(div2);
}
}
function addNewDiv(){
divArray[dCount] = new dyDiv();
dCount++;
}
function modifyTest(){
// after creation how does one manipulate a div inside an object
divArray[0].div1[0].style.border = "1px #00f solid"; // does not work
document.getElementById('div10').style.border = "1px #00f solid"; // does not work
document.getElementById('div1')[0].style.border = "1px #00f solid"; // does not work
document.getElementById(div1[0]).style.border = "1px #00f solid"; // does not work
}
function init(){
addNew.addEventListener("click", addNewDiv,false);
modTest.addEventListener("click", modifyTest,false);
}
window.addEventListener("DOMContentLoaded",init,false);
<button id="addNew">Create Dynamic Div</button>
<button id="modTest">Modify divArray[0]</button>
<div style="padding:50px" id="canvas"></div>