Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
Saving the state of the counter and active elements

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();
};
about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda