I am having trouble targeting rows newly created by hitting "Enter" with the code below. If I felt so inclined, I would like to keep hitting "Enter" to create new rows; however, hitting enter twice will only produce a maximum of one new row (from the original HTML rows). In attempt to debug the situation, I used a click event listener to console log the nodes associated with the table and found it odd that there are text nodes in between every row from the native HTML; however, these text nodes are not dynamically generated with every new row. Are these text nodes required for an HTML table to function properly?
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8;charset=utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$( document ).ready(function() {
$("tr").on("keydown", "input", function(){
keyDownLocation = this.selectionStart;
});
$("tr").on("keyup", "input", function(e){
if (e.key === "Enter") {
var tempSelect = this.value.substr(this.selectionStart);
this.value = this.value.substr(0, this.selectionStart);
$(this).parent().parent().after('<tr><td class="checkbox-td"><input type="checkbox" name="checklist-list" class="checkbox-box"></td><td class="item-td"><input class="input-item" type="text" value="' + tempSelect + '"></td></tr>');
$(this).parent().parent().next().find(".input-item").focus();
}
});
$("tr").on("click", "input", function(){
console.log($(this));
console.log($(this).parent().parent().parent()[0].childNodes);
});
});
</script>
<title>Title</title>
</head>
<body>
<table>
<thead>
<tr>
<th><input type="checkbox" name="checklist-list" class="checkbox-box"></th>
<th>Item</th>
</tr>
</thead>
<tbody>
<tr>
<td class="checkbox-td"><input type="checkbox" name="checklist-list" class="checkbox-box"></td>
<td class="item-td"><input class="input-item" type="text" value="Artificial"></td>
</tr>
<tr>
<td class="checkbox-td"><input type="checkbox" name="checklist-list" class="checkbox-box"></td>
<td class="item-td"><input class="input-item" type="text" value="Broken"></td>
</tr>
<tr>
<td class="checkbox-td"><input type="checkbox" name="checklist-list" class="checkbox-box"></td>
<td class="item-td"><input class="input-item" type="text" value="Casual"></td>
</tr>
</tbody>
<tfoot>
</tfoot>
</table>
</body>
</html>