Dynamically Loaded Content Through $.post Not Retaining Click Events
So, I'm trying to create a TODO list but I'm having problems with 'click' events once I dinamically load content. What I want to achieve is that, once I click an element, send the
Solution 1:
your click hanlder to delete row should be like this,you need to assign event handler again to newly added rows,
function delete_row(){
let li = $(this);
let id = li.attr("id");
$.post("list.php", {id: id}, function(data){
$("#todo-list").html(data);
//assigne the event handle again
$("#todo").on("click", "li",delete_row)
});
}
$(function() {
$.get("list.php", function(data){
$("#todo-list").html(data);
$("#todo").on("click", "li",delete_row)
});
});
Post a Comment for "Dynamically Loaded Content Through $.post Not Retaining Click Events"