Quiero saber si es posible añadir id automáticamente a todos los divs que se vayan agregando dentro del div padre, y así mismo estas id se vayan agregando solas en 'let historyElements' de javascript.
solo necesito eso, no quiero cambiar todo el codigo ya que se pierde la funcion que quiero.
let historyElements= [ '','',''];
for (let i=0;i < historyElements.length; i++) {
setTimeout(openHistory,2000 * i,historyElements[i]);
}
function openHistory(historyName) {
let x = document.getElementsByClassName("history");
for (let i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
document.getElementById(historyName).style.display = "block";
}
body{
margin: 0;
height: 100vh;
}
.loop{
height: 50%;
width: 100%;
background-color: #ddd;
display: flex;
align-items: center;
justify-content: center;
}
.loop div{
width: 100px;
height: 100px;
background-color: blue;
}
#id0{
background-color: #000;
}
#id1{
background-color: #ff0000;
}
#id2{
background-color: #ff0;
}
<div class="loop">
<div><!--id--></div>
<div><!--id--></div>
<div><!--id--></div>
</div>