So I'm working on some jQuery code to get new phone data displayed on the page.
So far everything is working except that the last phone number is the only one to be displayed no matter how many phone numbers I have. I discovered that it's because my $('.new_option').append(inputphone); is overriding the last one.
Here is the jsFiddle (not exactly the same code since I don't have a database Object, but produces the same problem): http://jsfiddle.net/leongaban/dvYMb/
The Variable (HTML with label + input):
var inputphone = $("<li><label></label><br/><input type='tel' pattern='[0-9]{10}' class='added_phone' name='' value='' autocomplete='off' maxlength='20' /></li>");
HTML DOM:
<li>
<ul class="new_option">
</ul>
</li>
The each loop:
$(profileData.phones).each(function(i) {
console.log(' ');
console.log('Phones: '+i);
console.log(profileData.phones[i].label);
$('.new_option').append(inputphone); //<-- The Issue
$('.added_phone').parent().find('label').text(profileData.phones[i].tag);
$('.added_phone').attr('id', "added_"+profileData.phones[i].tag+"phone" + i);
$('.added_phone').attr('value', profileData.phones[i].label);
});
Console:

Result on page:

My question is how do I make this line dynamically generate new fields with unique id's?
$('.new_option').append(inputphone);
Searching around here I see people saying use an object, but haven't been successful with that approach yet.
How would you handle this?