Can you save parent elements to localstorage and retrieve them after a page refresh?

I’m working on a project and I have a question that involves localstorage. Is it possible to save the parentElement of a childElement to a localstorage array, keep it therem, and retrieve the value on a page refresh? I’ll use my older project as an example that I modified a bit:

Let’s say that when you click the Submit button, you’re goal is to keep the forms element to stay in the list array as the HTML forms array element value and prevent it from turning into Prototype Object in the array.

The explanation may sound weird, but is there a way to keep a parentElement that is in a localstorage array as it’s original element, and not have the array default the parentElement value to a Prototype Object? Or is this beyond Javascripts capabilities? Thank you

Local storage stores strings and only strings. Not JavaScript objects, nothing except strings. You could store the HTML in a string, but this if faffy and a bit pointless: what you would store in your usecase is the state of your form, so the data input to it + something that represents what stage it is at so that you can just recreate it.

1 Like

So basically store the value of the form input, create an element that creates forms, save thr localstorage element value to localstorage, and recreate the element with the saved localstorage element?

I think i figured it out, actually

So this might be another weird question but this is interesting. So I made a program where If you click that first “no” block and then an empty black block the empty black block will get replaced with the “no” block. When you refresh the page, everything looks good on the surface, but when I try to click the newly created “no” block to try with another empty square it doesn’t seem to click. What’s also interesting is that when you console.log the document id of the new black “no” block, the console, the innerhtml is empty… I’m not sure if this relates to a concept that I have missed. Thank you

Actually, I may have figured it out but I still am down for a possible explanation for the future.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.