Hi all i have question how can i save the state of active cards as well as counter values the logic is active card + 1, differs from the rest in style repeated click on the same card - 1, the style returns to its original state. Right now I'm only saving the value of the clicked cards. But I need everything to stay in place after reloading the page
Code example
const counter: HTMLDivElement = <HTMLDivElement>document.querySelector('.counter');
const activeCard = get('cardState');
[image].forEach((el) => {
el.onclick = (evt) => {
evt.preventDefault();
const active = el.classList.toggle(style.otherImgActive);
if (el.classList.contains(style.otherImgActive)) {
set('cardState', (shopCart.innerHTML = `${Number(shopCart.innerHTML) + 1}`));
} else {
set('cardState', (shopCart.innerHTML = `${Number(shopCart.innerHTML) - 1}`));
}
};
});
fucn responsible for localstorage
const set = (name: string, value: string) => {
window.localStorage.setItem(name, JSON.stringify(value));
};
const get = (name: string) => {
return JSON.parse(window.localStorage.getItem(name) || subStr);
};
const remove = (name: string) => {
localStorage.removeItem(name);
};
const clean = () => {
localStorage.clear();
};