Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda