Skip to content
Advertisement

change array element value’s style

im building a to-do list but cant figure out how to keep my array values that have line-through decoration. the moment render method is called, the array is built from the start. means that if i delete an li, all other li that have been marked by the checkbox with a line-through, losing the decoration. what can i do to keep the line-through ? i tried so far in the markTask method to replace the original value with the value that have line-through on it but it didn’t work. basically what im trying to accomplish is by inserting the value with line-through, to be able to check if this value have the line-through style and after the render to be able to keep the checked checkboxes as checked.

my code so far:

JavaScript
JavaScript

Advertisement

Answer

it’s because you’re not tracking which tasks are done and you’re just pushing strings. for your createTask method you need to push an object with a done property to indicate which tasks have been done like so

JavaScript

update your render to account for tasks already done

JavaScript

in your constructor update your tasks variable to see this in effect

JavaScript

hope you get the general idea. I won’t do the entire implementation on markTask as this should be enough to give you a view of what the solution should be. good luck.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement