0

How can I add a clear button for each todo list individually in this code?

https://codepen.io/decryptus007/pen/VwvvbzV

14th Apr 2020, 4:34 PM
Dominic
Dominic - avatar
11 ответов
+ 2
// one function to modify, one function to add: var todoMaker = function(text) { var todo = document.createElement('li'); todo.textContent = text; var del_btn = document.createElement('button'); del_btn.className = 'del-todo-item-btn'; del_btn.innerHTML = '&times'; todo.appendChild(del_btn); todoList.appendChild(todo); del_btn.onclick = del_todo_item; } function del_todo_item(e) { var todo = e.target.parentNode; todo.parentNode.removeChild(todo); } // and for the css, at least: li button { float:right; } but if you don't plan to check if the todo-item string is blank (ie: empty or only spaces), you would probably need add this to the <li> css rules: li { height:1em; }
16th Apr 2020, 1:41 PM
visph
visph - avatar
0
Why a codepen link, as we have an excellent code playground here?... clicking this kind of link is annoying because leave the app and open a browser, where with a code playground link you'll just open the project in the app^^
14th Apr 2020, 8:02 PM
visph
visph - avatar
0
Noted. Thanks, so do you have any solution to my problem??
16th Apr 2020, 1:02 PM
Dominic
Dominic - avatar
0
Post your code here, and I would try to throw an eye upon it ;)
16th Apr 2020, 1:06 PM
visph
visph - avatar
16th Apr 2020, 1:10 PM
Dominic
Dominic - avatar
0
Oh, I've forgot to include your localstorage handling: I guess you could do it yourself, else let me know ;)
16th Apr 2020, 1:43 PM
visph
visph - avatar
0
It worked perferctly fine thanks. Pleasehow can I get your SM contact for further aides like this
16th Apr 2020, 2:15 PM
Dominic
Dominic - avatar
0
I don't know what's SM and I don't use those messageries nor any "social" network... If you want to contact me specifically you could either mention me, or post a comment on of my public code: I will receive notification and if I'm available, I will come to you ^^
16th Apr 2020, 2:19 PM
visph
visph - avatar
0
how am I gonna apply the local storage clear to the del button because when I applied the `localStorage.clear()` method it's clearing all list
16th Apr 2020, 2:23 PM
Dominic
Dominic - avatar
0
Update your live array, and save its json string once updated (the old json string stored in localstorage will be replaced by the new one).
16th Apr 2020, 2:26 PM
visph
visph - avatar
0
Thanks
16th Apr 2020, 2:46 PM
Dominic
Dominic - avatar