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

150
Visualizações
Trying to make a function hide and reveal 2 images

This is my code. I'm trying to hide another image behind another and make a button press switch which image is visible along with changing the href link.

function revealHQ() {
  var pilaf = document.getElementById('PilafHQ');
  var altaf = document.getElementById('altafsung');
  // get the current value of the hidden image's display property
  var displaySetting = altaf.style.display;
  // now toggle the clock and the button text, depending on current state
  if (displaySetting == 'block') {
    // hidden message is visible. hide it
    altaf.style.display = 'none';
    pilaf.style.display = 'block';
  } else {
    // if message is hidden. show it
    altaf.style.display = 'block';
    pilaf.style.display = 'none';
  }
}
.altafsung {
  border-radius: 15px;
  overflow: hidden;
  perspective: 1px;
  position: absolute;
  right: 0%;
  display: block;
}

.PilafHQ {
  border-radius: 15px;
  overflow: hidden;
  perspective: 1px;
  position: absolute;
  right: 0%;
  display: none;
}
<a href="https://tse1.mm.bing.net/th/id/OIP.9uW8U7EhqDOzl1-gONQjwAHaGj?pid=ImgDet&rs=1" target="_blank">
  <div class="PilafHQ"><img src="Images/Pilaf Castle Entrance cropped.png " alt="Pilaf castle entrance" width="250" height="250"></div>
</a>
<a href="https://altafs-bazaar.bertry.repl.co/" target="_blank">
  <div class="altafsung"><img src="Images/Altaf Bazaar Advert.png" alt="Altaf Sunglasses" width="250" height="250"></div>
</a>
<img src="Images/walkingbear.gif" alt="polar bear walking 😲" onclick="revealHQ();">

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

0

Use ID on the elements when you want to access byId

It is simpler to toggle the class

I gave the emoji an ID too

window.addEventListener("load", function() { // when page loads
  document.getElementById("toggleImage").addEventListener("click", function() {
    var pilaf = document.getElementById('PilafHQ');
    var altaf = document.getElementById('altafsung');
    // show one, hide the other
    altaf.classList.toggle("hide")
    pilaf.classList.toggle("hide")
  });
});
.altafsung {
  border-radius: 15px;
  overflow: hidden;
  perspective: 1px;
  position: absolute;
  right: 0%;
}

.PilafHQ {
  border-radius: 15px;
  overflow: hidden;
  perspective: 1px;
  position: absolute;
  right: 0%;
}

.hide {
  display: none
}
<a href="https://tse1.mm.bing.net/th/id/OIP.9uW8U7EhqDOzl1-gONQjwAHaGj?pid=ImgDet&rs=1" target="_blank">
  <div id="PilafHQ" class="hide"><img src="Images/Pilaf Castle Entrance cropped.png " alt="Pilaf castle entrance" width="250" height="250"></div>
</a>
<a href="https://altafs-bazaar.bertry.repl.co/" target="_blank">
  <div id="altafsung"><img src="Images/Altaf Bazaar Advert.png" alt="Altaf Sunglasses" width="250" height="250"></div>
</a>
<img id="toggleImage" src="Images/walkingbear.gif" alt="polar bear walking 😲">

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