I have this code which was working earlier. Then I started putting the code into small small functions and now it is not working. I can see that it is adding list item but automatically removing it also. Please guide -
<body>
<header>
<h1>Your Ration List</h1>
</header>
<div id="container">
<form class="shopList-form">
<input id="add" type="text" placeholder="Type new item here" />
</form>
<ul id="item_list">
<li id="base" class="hidden">
<form>
<input class="check" type="checkbox" /> <span class="item">Item</span>
</form>
<button class="delete_item hidden"></button>
</li>
</ul>
JQuery code -
$(document).ready(function () {
/* Get user input */
getItem();
function getItem() {
$('input#add').keydown(function (event) {
if (event.keyCode == 13) {
addItem();
}
});
}
function addItem() {
$('li#base').clone(true).appendTo('#item_list').removeAttr('id').removeClass('hidden');
$('ul#item_list>li:last>form>span').text($('input#add').val());
$('input#add').val("");
}
});
Full code can be found at this JSFiddle -