0

Is it possible to save dynamically added HTML elements with JavaScript on HTML page? For example, when I create some HTML element (div, p, li...) using JavaScript, then add it on a page, it appears on the page as it should be, but as soon as I reload or leave the page, and then get back - all those elements disappear. So, how can I do so that they do not disappear after reloading or leaving page (If such is possible).

isherwood
  • 58,414
  • 16
  • 114
  • 157
Yura Shtefanko
  • 139
  • 1
  • 2
  • 6
  • show some code so that everyone can understand and help... – DecPK Apr 13 '21 at 15:23
  • 3
    You have to look for methods of persistence across HTTP requests. Cookies, localStorage, sessionStorage etc. Research your options, pick the one best suited to your use case, and try to implement it. – mason Apr 13 '21 at 15:24

1 Answers1

0

It is not possible without some backend interaction. But if you need it only for one client (one browser) you can store some details to localStorage and use it on the next load. You have to be aware only one client will be able to see it.

Akif Hadziabdic
  • 2,692
  • 1
  • 14
  • 25
  • "It is not possible without some backend interaction." Sure it is possible, the rest of your answer contradicts that sentence. There's localStorage, sessionStorage, cookies, possibly other things I'm not thinking of. – mason Apr 13 '21 at 19:39
  • cookies are backend interaction, localStorage and sessionStorage are solutions only for one client, not a general solution. – Akif Hadziabdic Apr 13 '21 at 21:00
  • Just because cookies end up going through the server doesn't really make them "backend". And you're presuming they're seeking a solution that works across multiple clients instead of just one client? Possibly....but there's no evidence here to support that position. – mason Apr 13 '21 at 21:07