I have a list of tasks with id #tasks with delete anchors with class .deleteTask next to each list element. This elements and its delete links are created dynamically by ajax. So if I want hook some handlers to elements I use it like this:
$('#tasks').on('click', '.deleteTask', function (event)
{
if( ! confirm('Are you sure?') ) event.preventDefault();
});
But it seems the click event on anchors with class .deleteTask is triggered before the click on parent #tasks element. So I can't call preventDefault() on it. I think it is because of bubbling. But how can I trigger preventDefault() on anchors which are dynamically created?
Here is the example https://jsfiddle.net/dyLa915b/1/