I am adding and removing items from a ul. However, I cannot remove items that were just added. I am assuming I need to register the event when the item is added. How to do this please?
If you are registering an event handler for every li
item in your ul
, use the .live() function. This will register the same handler for every new li
item that shows up on the page.
For example,
$("li").live("click", function(){
$(this).remove();
});
If this doesn't answer your question, could you edit it to be a bit more clear about what you're trying to do?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.