Question 1.
When installing cookies, you can specify the expires parameter for expires . Then they will live as long as you tell them, unless of course the server overwrites.
If you specify a date in the past, the cookie will be deleted immediately. If you do not specify, the cookie is considered to be session and when it closes the browser goes out.
You cannot see when the cookie expires in js. But you can through the developer console. In chrome, this is on the "Resources" tab
Endless cookies can not be set, but you can tell them to live a couple of years, this is enough for your eyes.
You can read more details like here.
Question 2.
Something like that:
var now, expirationDate = new Date(), newCookie; // Страшное число - это один день в миллисекундах. expirationDate.setTime(now.getTime() + 24*60*60*1000); newCookie = "myCookie=testCookieValue;expires=" + expirationDate.toUTCString(); document.cookie = newCookie;
Point 3.
Cookies should be used for the data that the server should know. If this is information that the server does not need at all, you should use localStorage or sessionStorage . The data in sessionStorage live browser session. The data in localStorage live until they are killed forcibly. That is, there is no expirationDate parameter for localStorage , you can implement it yourself if you wish.
Storaj has functions setItem(key, value) and getItem(key, value) with which you can get and remove values from them.
That is, to solve your main task:
By the time your item is loaded (onLoad), you need to check the data that is stored in the stack and hang the necessary class depending on it.
When you switch a class on an item, you need to change the value in the store accordingly.