I want to add different items to a list and then delete each one of them using a 'click' event. However, the bellow snippet only allows me to delete those preset items but not those I have added. Could anyone tell me what I'm doing wrong ?
HTML
<body>
<div id="page">
<h1 id="header">List</h1>
<h2>Buy groceries</h2>
<ul>
<li id="one" class="hot"><em>fresh</em> figs</li>
<li id="two" class="hot">pine nuts</li>
<li id="three" class="hot">honey</li>
<li id="four">balsamic vinegar</li>
</ul>
<div id="newItemButton"><button href="#" id="showForm">new item</button></div>
<form id="newItemForm">
<input type="text" id="itemDescription" placeholder="Add description..." />
<input type="submit" id="addButton" value="add" />
</form>
</div>
<script src="js/jquery-1.11.0.js"></script>
<script src="js/form.js"></script>
jQuery
$(function() {
var $newItemButton = $('#newItemButton');
var $newItemForm = $('#newItemForm');
var $textInput = $('input:text');
$newItemButton.show();
$newItemForm.hide();
$('#showForm').on('click', function(){
$newItemButton.hide();
$newItemForm.show();
});
$newItemForm.on('submit', function(e){
e.preventDefault();
var newText = $textInput.val();
$('li:last').after('<li>' + newText + '</li>');
$('li:last').attr('class','hot');
$newItemForm.hide();
$newItemButton.show();
$textInput.val('');
});
var $listItems = $('li');
$listItems.on('click', function(){
$(this).animate({
opacity: 0.0,
paddingLeft: 50
}, 500, function(){
$(this).remove();
});
});
});