I'm pretty new with javascript and when it comes to creating loopings I totally lose myself, the code below is to create the elements with each click and number the id
and the text, but I'm having difficulties with that, I I managed to solve with an input and adding the quantity, but this is not the result that I need, how should I proceed? If possible explain the changes, Thanks.
document.getElementById("add1").onclick = function clone(){
var qt = 1;
var container = document.getElementById("saida1");
while (container.hasChildNodes()) {
container.removeChild(container.lastChild);
}
for (i=0;i<qt;i++){
var input = document.createElement("input");
var div1 = document.createElement("div");
var div2 = document.createElement("div");
var div3 = document.createElement("div");
var label = document.createElement("label");
div1.className = "linha";
div2.className = "coluna1";
div3.className = "coluna2";
label.htmlFor = (i+1)
label.textContent = "Texto " + (i+1) + ": ";
input.className = (i+1);
input.name = "inp";
input.type = "text";
container.appendChild(div1);
div1.appendChild(div2);
div2.appendChild(label);
div1.appendChild(div3);
div3.appendChild(input);
}
}
<div id="saida1"></div>
<button id="add1">ADD</button>