I asked another question on this question and got an answer, but still managed to ruin it. I have a for loop and I want to create clones of the template in a for loop. I would like each id to be replaced by id + 0 for the first time through a loop. So the text field with id tFirstName will be tFirstName0 , and id tLastName will be tLastName0 and so on ... Then for the next clone, and then next time through the loop will be tFirstName1, tLastName1, ect ..
The problem with this code is that i adds one for each text field, so in the first template id is tFirstName0 , tLastName1 , ect ..
I am looking for - if someone has a suggestion to keep the shape of i uniformly through the for loop and then increase and then remain uniform in the next cycle
var NumofClones = (4 * 1); for (i = 0; i < NumofClones; i++) { var newrow = $('._template').clone().removeClass('_template'); newrow.find('input[type=text]').attr('id', function (i, oldID) { return oldID + i }); $('.placenewrows').append(newrow); }
source share