Using local storage to save the state of the innerhtml of a element

Hi All,

I’m currently building an app in which the user presses a button and this changes the innerhtml of an element. What I want to happen is the user to only have to press the button once and every time they load the web app on their device, it changes to the innerhtml stored in their local storage.

I’ve seen an example on here where a user can use local storage to store the scene (thanks @DBear) but I can’t find anything for storing the value, in my case innerhtml, of an element.

Can anyone help with this? I’ve never used local storage before,

Thanks

Chris

Hi all again,

I’ve worked out how to do this! Just create a variable with the local storage tag, link this to the element you want to change and run the javascript upon screen load. Here’s an example of this:

local storage example.zip (16.9 KB)

Chris

3 Likes

@Chriswhardy,

See you don’t need us to work it out for you :smiley: :smiley:

Although it would be quicker, maybe, for us to show you :slight_smile: even though this time it wasn’t :stuck_out_tongue:

Well done for working out on your own. :+1:

N.B Just to elaborate a little …
Local Storage is an object that consists of keys and value

localStorage.setItem('key', 'value');
// also localStorage.key = value;

So, technically it’s not a “variable” with a “tag” :wink:

to get the stored item use

localStorage.getItem('key');
// also localStorage.key;
2 Likes

Thanks @DBear :slight_smile: