To-do list

Hi there! I'm trying to create a todolist using js. • I have added the data to local storage • Get the data from local storage and show it on the ui • Now in trying to create a function to delete the data from the ui and from the local storage but it deletes the whole data from local storage
function deleteItem(para,deletebtn){
para.remove();
deletebtn.remove();
localStorage.removeItem("userData");
}
function deleteItem(para,deletebtn){
para.remove();
deletebtn.remove();
localStorage.removeItem("userData");
}
• I'd appreciate if you help me to resolve this issue and other tips Github repo: https://github.com/Myragull/Todolist Live at: https://myragull.github.io/Todolist/
GitHub
GitHub - Myragull/Todolist: A simple todolist project built with ht...
A simple todolist project built with html ,css and javascript - Myragull/Todolist
14 Replies
Mannix
Mannix7d ago
you need to get the data from localstorage turn it back into array then remove selected item from that array and turn the array back to a string a save it in localstorage. You are now removing all entries
Myra
MyraOP7d ago
I have updated the changes can you check them?
Mannix
Mannix7d ago
looks good and it is working so job done 🙂
Myra
MyraOP7d ago
And also is there any other thing that needs to be fixed Like i try to insert the code anywhere to make it works
Chief
Chief7d ago
would you like to work on a bug? @Myra Enter 2 tasks with the same name. Example: learn html learn html And try to delete and refresh the browser. Both of your entries would be deleted. Folks might say that it is unnecessary that you would have 2 same tasks on a single todo list, which is fine. I am trying to make you understand that, this is good, but always try to assign some id while you are inserting the tasks.
Myra
MyraOP7d ago
Sure
Chief
Chief7d ago
So whenever you press delete, you extract the id instead of the value that the user is trying to delete, and delete that particular record which has the id in the array.
Myra
MyraOP7d ago
Ok
Chief
Chief7d ago
Makes sense?
Myra
MyraOP7d ago
Yes, I'm trying to do
Chief
Chief7d ago
I have just given you the starting point, there are some other things which you need to consider.
Myra
MyraOP7d ago
I have tried to implement the things that you told me in my code would you please check them? @Chief
Chief
Chief7d ago
perfect! works fine. hope you learnt something. good work
Myra
MyraOP7d ago
Yes, thaks for the help! @Chief

Did you find this page helpful?