Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
How to make the sessionstorage remember the result of click?

How to make the session storage remember the result of click? Now it's now working and I don't know why.

I want to add a key to the session, and when the key is in the session, the popup is not shown.

Thank you in advance!

let object = document.querySelector('.object');
let tap = document.querySelector('.tap');

function addSessionKey() {
    sessionStorage.setItem('hide', true);
}
function hideObject() {
  for(let i=0; i<sessionStorage.length; i++) {
    let key = sessionStorage.key(i);
    object.classList.add('none');
  }
  hideObject();
}

tap.addEventListener('click', addSessionKey);
tap.addEventListener('click', hideObject);
section {
  height: 100vh;
  background: #ccc;
  display: flex;
  align-items: center;
  justify-content: center;
}
div {
  padding: 1rem 3rem;
  background: #999;
}
bottom {
  display: block;
  padding: 1rem;
  background: #666;
  cursor: pointer;
}
.object.none {
  display: none;
}
<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <title>Document</title>
  </head>

  <body>
    <section>
      <div class="object">
        <h2>Object</h2>
        <bottom class="tap">Tap</bottom>
      </div>
    </section>
  </body>

</html>

about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda