You must not use the same identifier for different elements
, , /
jQuery :
$('<ELEMENT TAG/>',{
ATTRIBUTE: VALUE
});
jQuery $.each
$('#append').on('click', function(){
$('<div/>', {
'class': 'inputs',
html: '<span class="count"></span><input type="text" class="time" name="0" value="00:00:00"/><button>X</button>'
}).appendTo('#inputs');
resetInputsCount();
});
$('#inputs').on('click', '.inputs button', function(){
var $this = $(this);
$this.parent().remove();
resetInputsCount();
});
function resetInputsCount(){
$('#inputs div.inputs').each(function(i){
var $this = $(this);
$('.count', this).text((i+2) + '.) ');
$('input', $this).attr('name', i+2);
});
}
JSFiddle