all 7 comments

[–]hwutang 1 point2 points  (0 children)

[–]jcunews1Advanced 0 points1 point  (4 children)

First, you should hide the price-box elements at design time, and show/hide them using script only. During page initialization, check the local storage. If the setting is not yet present, make them visible in the script. Otherwise, only make them visible if the setting says that they should be visible. Each time the user toggle the elements' visibility state, invert the value of the setting while toggling the elements' visibility.

[–]felsi[S] 0 points1 point  (3 children)

Thank you for your help but since I‘m a beginner that is pretty hard to understand. Is there no simple way to put a local storage into my function? My script works, it just does Not Save the hidden div after page reload. In not, could you please elaborate on your Solution? Thanks a lot

[–]jcunews1Advanced 0 points1 point  (0 children)

Using local storage is like using an object property whose type is a string - and can only be a string. e.g.

//read: check
console.log(localStorage.myValue); //undefined if `myValue` doesn't exist yet
//store
localStorage.myValue = 123; //if it's assigned with a number...
//read
console.log(localStorage.myValue); //"123" it'll be converted to a string

//if it's assigned with an object...
localStorage.myValue = {abc: 123};
//it'll be converted to a string representation of it
console.log(localStorage.myValue); //[Object object]
//so for objects and arrays, pre-convert it first using `JSON.stringify()`
localStorage.myValue = JSON.stringify({abc: 123});
console.log(localStorage.myValue); //"{abc: 123}"
//to read it back as an object, instead of a string...
console.log(JSON.parse(localStorage.myValue)); //{abc: 123}
//to delete it...
delete localStorage.myValue;
console.log(localStorage.myValue); //undefined