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

209
Vistas
How do I get an image stored in a javascript variable, to display in an HTML code?

How do I get an image stored in a javascript variable, to display in an HTML code?

Say for instance, my image is stored in a variable called flowers as seen in the below javascript code:

<script>
     var flowers = "myFlowers.gif";
</script>

In the following HTML code, I reference the flowers variable in my img src in order to display the image but cant seem to get this to work.

<img src= flowers  class="card-img-top" id="flowers">

Please help, What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can't insert it directly like that. Instead you set the attribute src through javascript.

let flowers = "https://picsum.photos/200/300";
document.querySelector('#flowers').src = flowers;
<img  class="card-img-top" id="flowers">

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