Remove() not working on new elements [duplicate]
- by user3317470
This question already has an answer here:
In jQuery, how to attach events to dynamic html elements?
9 answers
I'm making a simple to do list. It's mostly working and finished. When you click on list elements the object gets removed and you can create new list elements through the text input at the bottom. The only problem is the new list elements can't be removed when you click them for some reason.
Here's the code:
http://jsfiddle.net/dnhynh/7psqndwL/20/
$(document).ready(function(){
$("li").click(function(){
$(this).remove();
});
$("button").click(function(){
var entry = $("#entry").val();
$("<li></li>", {
text: entry
}).appendTo("#list ul");
$("#entry").val("");
});
});