Try this:
$('#myDiv').on('keyup', 'input', function() {
if($(this).val() == ''){
$(this).next().remove();
return;
}
else if($(this).next().val() == '') {
console.log('here');
return;
}
var newTxt = $(this).clone();
var id = newTxt.attr('id');
newTxt.attr('id', 'txt_' + (parseInt(id.substring(id.indexOf('_') + 1))));
newTxt.val('');
$(this).parent().append(newTxt);
});