valerio0999 valerio0999 - 1 year ago 27
Javascript Question

using localstorage to keep html on page refresh not working

I'm trying to integrate this fiddle: in a fiddle I'm doing:

Basically you have a basket with some items inside of it, you can add or remove them. What I want is that, on page refresh, the

of the
is kept in local storage. I'm stuck here:

I've put the
variable in the click handler because otherwise, the var wouldn't update itself but now I'm guessing that the final local storage code

if(localStorage.getItem('toDoData')) {
forLocalStorage = localStorage.getItem('toDoData');

is not working because it can't retrive the variable?

I've tried moving around things but I'm stuck here. what am i doing wrong?


You need to update DOM once your variable is set, e.g:

  if (localStorage.getItem('toDoData')) {
    forLocalStorage = localStorage.getItem('toDoData');