Im trying to create a facebook style newsfeed. Using jquery, I’ve managed to set it up so that users can add new newsitems and then delete them without refreshing the page. The delete function works fine on the news items that I have added directly into the HTML, but I can’t delete items that I have dynamically created using the textfield.
This is a pretty complicated problem, so I recreated it on jFiddle: http://jsfiddle.net/Gefgj/
To make it work for the dynamically added entries, change this line:
to this:
Or if you’re using jQuery 1.7, you can use the new `.on()’ method.
You can see it work here: http://jsfiddle.net/jfriend00/tbaAU/
.live('click', ...)will hook up to newly created items as well as pre-existing items..click(...)will only hook up to items that exist at the time you run that line of code. See the jQuery doc for.live()for more info or the jQuery doc for .on.