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

131
Vistas
How to clear image input in each loop of jQuery?

I want to clear the image which is invalid image format. I've tried multiple times but didn't work. How can I achieve it. Using jQuery 3.6.0

$(':file').change(function(){
        var fileArray = this.files;
        var validImageTypes = ["image/gif", "image/jpeg", "image/png"];
        $.each(fileArray,function(i,v){
          type = v.type;
          if ($.inArray(type, validImageTypes) < 0) {
            alert('Only jpg, jpeg and png is allowed.');
            // here i want to clear the image which is selected
            };
        })
        });

I've tried using $(this).val("") but not working. Please help.

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

0

this points the function called in each.

Use an arrow function to automatically bind to the parent context, (the file element).

$(':file').change(function() {
var fileArray = this.files;
var validImageTypes = ["image/gif", "image/jpeg", "image/png"];
$.each(fileArray, (i, v) => {
    type = v.type;
    if ($.inArray(type, validImageTypes) < 0) {
        alert('Only jpg, jpeg and png is allowed.');
        // here i want to clear the image which is selected
        $(this).val(""); 
    };
})});
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