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

167
Visualizações
Toggle iframe js function not working properly

I have this js function:

var iframeShowing = false;

async function show() {
 
    var iframe1 = document.getElementById('help-popup');
    iframe1.style.display = iframeShowing ? 'flex' : 'none';
    iframeShowing = !iframeShowing;

  
}

The problem is that I need to click 2 times to actually show the iframe and make it work properly. After I click 2 times, it works properly(every click shows and hides the iframe). Try it on the website and you'll understand. This is the html code:

<i class="fas fa-question-circle" id="questionmark" onclick="show();"  >

This is the current website: https://personal-website.krix12.repl.co/ The above mentioned function is called when the blurple question icon is clicked. How can I make it work on the first click?

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

0

You can just use DOMTokenList.toggle() to toggle between flex and none:

function toggle() {
  var iframe1 = document.getElementById('help-popup');
  iframe1.classList.toggle('hide');
}
iframe {
  display: flex;
}

.hide {
  display: none;
}
<div><i class="fas fa-question-circle" id="questionmark" onclick="toggle();">?</i></div>
<iframe id="help-popup" class="hide"></iframe>

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