Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!