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

270
Vistas
How can i delete images preview each time file input is clicked?

I'm trying to reset the image preview created by file input each time the upload button clicks. I'm new to JS so forgive me if I missed the obvious.

This is a code snippet I found to show the preview:

$(function() {
var imagesPreview = function(input, placeToInsertImagePreview) {
if (input.files) {
var filesAmount = input.files.length;
for (i = 0; i < filesAmount; i++) {
var reader = new FileReader();
reader.onload = function(event) {
$($.parseHTML('<img class="padit">')).attr('src', event.target.result).appendTo(placeToInsertImagePreview);
}
reader.readAsDataURL(input.files[i]);
}
}
};
$('#gallery-photo-add').on('change', function() {
imagesPreview(this, 'div.gallery');
});
});

This is my HTML:

<div class="upload-field">
        <label class="bcard-label" for="gallery-photo-add">
        <input id="gallery-photo-add" type="file" accept="image/*" value="" multiple>
          <i class="fa fa-2x fa-camera"></i>
          </label>
      </div>
      <div class="gallery">

      </div>

This is the CSS:

.upload-field{
  display: flex;
  justify-content: center;
  align-items: center;
  max-width: 95%;
  border: 4px dashed grey;
  height: 100px;
  margin: auto;
}

.gallery{
  display: inline-block;
  column-count: 2;
  margin: 15px;
}

img.padit{
padding: 5px;
}

And with my very little knowledge in JS I tried to complete the task with this snippet:

const element = document.getElementById("gallery-photo-add");
element.addEventListener("click", function() {
document.getElementById("padit").remove();

Any ideas where am I wrong? Thanks :)

about 4 years ago · Santiago Gelvez
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