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

157
Visualizações
How to determine the drop zone for a multi drag-and-drop file uploader?

Question

How do I accurately determine which drop zone the file was dropped into?

Background

I'm creating an HTML page with vanilla JavaScript that has 2 drop zones for 2 different file types, and depending on which drop zone the file is sent to, the files should ultimately be sent to a different endpoint.

Drop Zone HTML

  <div class="drop-area" id="drop-area-1" >
    <form class="my-form" id="form-1">
      <p id="p-1">Drop Area 1</p>
    </form>
  </div>

  <div class="drop-area" id="drop-area-2" >
    <form class="my-form" id="form-2">
      <p id="p-2">Drop Area 2</p>
    </form>
  </div>

Javascript

I won't put in all the boilerplate stuff like preventDefaults, but I'll show the drop handler function

  function handleDrop(e) {
    var dt = e.dataTransfer;
    var files = dt.files;
    let fileType = e.target.innerText;
    handleFiles(files, fileType)
  }

Problem

Depending on if I release the drag in the div, the form, or the p, I get different values for e.target.id

For example, if I add a console.log(e.target.id), I can get the following values depending on where I do the actual drop:

  • drop-area-1 / drop-area-2
  • form-1 / form-2
  • p-1 / p-2

So what value in the event can I use to say regardless of where the drop occurs that it happened in drop?

Current solution

The only way I've managed to get it to work consistently is by using e.target.innerText which feels like a hack.

about 4 years ago · Juan Pablo Isaza
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