Tuesday, 27 August 2013

Generate text in loop and order number

Generate text in loop and order number

I have a dive which is getting shown on click. When you click on the add
person button it clone and add the .loop div.
What I need is there is a heading text in that loop div (person 1), I need
this text to be updated for each loop. For example person1,person 2,
person 3 ...
Here is my code and fiddle
$(document).ready(function() {
clicks = 0;
$('div.test').on('click', function () {
$('.attnd2').show();
$('div.loop').show();
if ($('div.loop').length < 5) {
clicks++;
if(clicks>1){
newLoopDiv =
$($('div.loop')[0]).clone().appendTo(".container");
$('input', newLoopDiv).each(function (index,
element) {
$(element).attr('name', $(element).attr('name') +
clicks);
});
}
else{
newLoopDiv = $($('div.loop')[0]).appendTo(".container");
$('input', newLoopDiv).each(function (index,
element) {
$(element).attr('name', $(element).attr('name') +
clicks);
});
}
}
$( ".remove" ).click(function() {
$(this).closest('.loop').remove();
});
});
});

No comments:

Post a Comment