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

180
Visualizações
how to store a function so it works only after clicked and results stays after refreshing the page?

    function hd() {
        document.getElementById("Y").style.display = "none";
    }
body {
display:grid;
place-content: center;
height:100vh;
overflow:hidden;
}
<div id="Y">i will be hidden</div>
<br>
<button onclick="hd();">click me</button>


The important thing is to store the function so it works even user refreshes the page I tried to use cookies but it did not work by just calling the function

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can set a flag with localStorage and then check if this flag has already been set and call the function again at startup.

 function hd () { document.getElementById("Y").style.display = "none"; localStorage.setItem("hidden", "yes"); } if (localStorage.getItem("hidden")) { hd(); }
about 4 years ago · Juan Pablo Isaza Relatório
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