Reputation: 23
Here is my Html part
<input type="text" class="demo" id="" value="" />
<input type="text" class="demo" id="" value="" />
<input type="text" class="demo" id="" value="" />
<input type="text" class="demo" id="" value="" />
<input type="text" class="demo" id="" value="" />
My jquery
$('.demo').attr('id', function (i) {
return 'Sample_' + (i + 1);
});
Now I need this "i" to start from 5 rather than 0 so my result will be starting from Sample_6, Sample_7 etc..
How can i do that???
Upvotes: 1
Views: 212
Reputation: 1
Simply:
var a = 5;
$('.demo').attr('id', function (i) {
if(i == 0) {
a++;
return 'Sample_' + (a);
}
else
return 'Sample_' + (i + 1);
});
Upvotes: 0
Reputation: 253318
I'd suggest:
$('.demo').attr('id', function (i) {
return 'Sample_' + (i + 5);
});
Upvotes: 1