Check List marks and deletes only existing items

Asked

Viewed 31 times

1

I have a check-list done in js, where the user type the task and it appears in the list. But I can only mark as "task completed" or "delete task" existing tasks, that is, when I include a task I can not exclude or mark it.

Follows codepen: https://codepen.io/fmm312/pen/mXBqKd

1 answer

1


Delegation problem. Change the Event handlers:

$(document).on('click','.checked-task',function(){
    $(this).parent().find('.name-task').toggleClass('name-task-toggle');
});

$(document).on('click','.remove-task',function(){
    $(this).parent().hide('slow');
});

Elements added dynamically are not in the DOM. So the syntax above can hear new elements.

There are already some answers with the same problem: answer 1, answer 2, answer 3.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.