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

115
Views
Change element to an iFrame onclick

So, I created this:

https://codepen.io/Blvcksquid/pen/yLpdBoO

Now I want a js function thats assigned to the onclick button function "schach()". The function should change the "box" element on click to an iframe element with the url "schach.coach".

I tried to write the function on my own, but the variable doesnt work:

function schach() {
  let content = "  <iframe  class="box2" src="https://schach.coach" style="border:3px #black solid"; name="myiFrame" scrolling="yes" frameborder='1' marginheight="0px" marginwidth="0px" height="450px" width="240px" allowfullscreen></iframe>"
      document.getElementById("box").innerHTML = "content"
     }

I am sure something's wrong with my content variable or am I even using the wrong function? Please help, I am a beginner and hungry to learn.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It looks like you are assigning a string to the box instead of the actual content of the variable. Try this line instead:

document.getElementById('box').innerHTML = content;

Notice that I have removed the double quotes from the word "content"

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!