Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

110
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda