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

606
Vistas
Select images and display using JavaScript

This will select the targeted files and cycles through selected files and stops on the last file. How can the images be displayed without being over written?

//Function below is in the DOM area
function showDirectory(){
   var myFiles = document.getElementById("files");
   for(var i=0;i<=myFiles.files.length; i++){
   var x = myFiles.files[i].name;
   document.getElementById("demo1").src= x;
   }
}
//This is in a div in the body
<input type="file" id="files" name="files[]" multiple/>
<button onclick="showDirectory();">Show files in the Directory</button>
<img id="demo1" src=""  style="width: 40px; height: 40px;"><br>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The syntax document.createElement() is used to actually create new DOM elements, so that you don't have to override old ones. In your case, replace document.getElementById("demo1").src= x; with

let e = document.createElement("img");
e.src = x;
document.getElementById("demo1").appendChild(e);

This code will create a new DOM element of type image, it will set its source to whatever your for loop outputs, and then it will append the img to the div that you have created.

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