2

I have been creating a to do list over the last few days although I've run into a small bug that I just can not fix.

The problem is... When I move a To Do from the "current to dos list" to the "Completed to dos list" they can not be deleted individually on the "completed to dos" page through the bin icon.

I am new to this so my code may be a mess or you may see some bad practices. If you do notice this feel free to say that as well so i can learn. :)

VIEW FULL PROJECT HERE! https://codepen.io/beezeecode/pen/EvmBGo

// Transfer Li from Current to completed.
 $("ul").on("click", ".move", function(){  
  $(this).parent().remove().appendTo( "#container1");
  $(this).parent().removeClass("move comp").addClass("appendToDo comp2 comp1");
  $(this, ':nth-child(2)').remove();
});

// Delete a To dos present in the COMPLETED list. 

$("#delComp").on("click", ".delSpan", function(){
   $(this).fadeOut(500,function(){
   $(this).remove();
  });
});

Thanks in advance for any help!

3 Answers 3

1

The issue is because when you move the li elements between lists you're appending them to the containing div instead of the ul. This in turn means that the delegated event on the delete button is not attached.

To fix this amend the appendTo() call in your .move handler:

$(this).parent().remove().appendTo("#delComp");

Updated Codepen

Sign up to request clarification or add additional context in comments.

Comments

0

The main problem is that the Completed Todo is not in an UL anymore, so the li are dangling and no parent like ul, so the selector used here $("ul").on("click", ".delSpan", won't work again,

so the fix is to do , but observe the changes made to the appendTo #container1 > #delComp

    // Transfer Li from Current to completed.
$("ul").on("click", ".move", function(){  
  $(this).parent().remove().appendTo( "#container1 > #delComp");
  $(this).parent().removeClass("move comp").addClass("appendToDo comp2 comp1");
  $(this, ':nth-child(2)').remove();
});

Comments

0

The issue is that your <li> is being moved into the #container1 instead of the #delComp <ul>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.