Reputation: 95
Is it possible to save element to local storage then call it from it this an example for what I'm trying to do
let div = document.createElement("div");
localStorage.setItem("div",div)
document.body.appendChild(localStorage.getItem("div"))
Upvotes: 1
Views: 1517
Reputation: 944528
Not as such.
Values in local storage must be strings and DOM elements are not strings.
You would need to serialise the data. Most applications would use JSON and store business data rather then anything that directly represents the rendered view but you could store HTML source code.
Upvotes: 1