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

144
Visualizações
No se puede escuchar el evento dragend en div

Tengo un div donde simplemente quiero escuchar el evento dragend pero, por alguna razón, no funciona. Quiero iniciar sesión en la consola cuando el cuadro azul se cae dentro del rectángulo, pero no da nada...

Aquí está el código:

 <!DOCTYPE html> <html> <head> <style> #a { width: 350px; height: 70px; padding: 10px; border: 1px solid #aaaaaa; } #drag1 { background-color: blue; width: 100px; height: 70px; } </style> </head> <body> <p>Drag the blue box into the rectangle and wait for the console log:</p> <div id="a"></div> <br /> <div id="drag1" draggable="true"></div> </body> <script> dropArea = document.getElementById("a"); dragger = document.getElementById("drag1"); dropArea.addEventListener("dragend", () => { console.log("Hello....."); }); </script> </html>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

El evento Dragend se inicia desde el arrastre del elemento cuando termina de arrastrarlo.

debe colocar el evento dragend en el elemento de arrastre y no en el área de colocación

cambio

 dropArea.addEventListener("dragend", () => {

por

 dragger.addEventListener("dragend", () => { 

 dropArea = document.getElementById("a"); dragger = document.getElementById("drag1"); dragger.addEventListener("dragend", () => { console.log("Here....."); });
 <!DOCTYPE html> <html> <head> <style> #a { width: 350px; height: 70px; padding: 10px; border: 1px solid #aaaaaa; } #drag1 { background-color: blue; width: 100px; height: 70px; } </style> </head> <body> <p>Drag the blue box into the rectangle and wait for the console log:</p> <div id="a"></div> <br /> <div id="drag1" draggable="true"></div> </body> </html>

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