$("li").on("click",'span',function(event){
event.stopImmediatePropagation();
$(this).parent().fadeOut(function(){
$(this).remove();
});
});
So I have used a click listener for deleting a to-do.
The to-do html contains nested span inside the li for the trash icon.
For the 'click' listener for span I've used the 'li' as the parent element. But the event listener doesn't work anymore for dynamically added elements.
I've observed that it works perfectly if I chose the parent element as 'ul' :
$("ul").on("click",'span',function(event){
event.stopImmediatePropagation();
$(this).parent().fadeOut(function(){
$(this).remove();
});
});
Here is the code snippet: https://codepen.io/AjayKudva/pen/MBgrdW