add and focus new field
by reeson46
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<form action="">
<div id="items">
<input id="sub" type="text" name="subtask">
</div>
<input type="submit" value="submit">
</form>
JavaScript
$(document).ready(function () {
$("#items").keypress(function(e) {
if (e.which === 13)
{
e.preventDefault();
$('#items').append('<div><input id="sub" type="text" name="subtask">' +
'<input type="button" value="delete" id="delete" /></div>');
$(this).next().focus();
}
});
$("body").on('click', "#delete",function(e){
$(this).parent('div').remove();
})
});