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

146
Visualizações
How to fade-in same DIV when click different button?

basically I want to visually let the user know that the data has change when he clicked a button.

Everytime user click a different button, same div has to disappear and fade-in again.

I have tried toggle and transition but it's not workig, you can see it works only when you click for the first time!

Thank you!

function showMe(n){          
      let myDiv = document.getElementById('myDiv');      
      myDiv.innerHTML = n==1?"Hello Data":"Another Data";
      myDiv.style.opacity = '1';
    }
#myDiv {
  width: 300px;
  height: 300px;
  border: 2px solid black;
  opacity: 0;
  transition: opacity 1s;
}
<div id="myDiv"></div>
  <button onclick="showMe(1)">ShowData</button>
  <button onclick="showMe(100)">AnotherData</button>

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

0

function showMe(n){          
      let myDiv = document.getElementById('myDiv');      
      myDiv.style.opacity = '0';
      setTimeout(function(){ 
        myDiv.innerHTML = n==1?"Hello Data":"Another Data";
        myDiv.style.opacity = '1';
      }, 1000);
      
    }
#myDiv {
  width: 200px;
  height: 200px;
  border: 2px solid black;
  opacity: 0;
  transition: opacity 1s;
}
<div id="myDiv"></div>
  <button onclick="showMe(1)">ShowData</button>
  <button onclick="showMe(100)">AnotherData</button>

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