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

254
Visualizações
Javascript deprecated ondrop="drop(event)" equivalent with listeners

I've got a quite easy kanban board in my application, in which cards can be drag and dropped into lanes.

everything works fine but my IDE suggests "Deprecated symbol used" on this HTML line, particularly on the "event" word:

<div class="card draggable shadow-sm" id="cd1" draggable="true" ondragstart="drag(event)">

I've read that now I should achieve the same result using listeners, but since I'm a JavaScript beginner I'm having quite some problems with the implementation.

This is before (working but deprecated):

//HTML
<div class="card draggable shadow-sm" id="cd1" draggable="true" ondragstart="drag(event)">

//JS
const drag = (ev) => {
    ev.dataTransfer.setData("text/plain", ev.target.id);
}

This is my attempt (not working):

//HTML
<div class="card draggable shadow-sm" id="cd1" draggable="true">

//JS
//add listeners to draggable cards
let cd = document.querySelectorAll('.draggable');
cd.forEach(card => {
        card.addEventListener('dragstart', (ev) => drag(ev));
    }
);

function drag(ev) {
    ev.dataTransfer.setData("text/plain", ev.target.id);
}

Any help is appreciated, I've tried following this Stackoverflow but couldn't find a working solution for my case. I would strongly prefer not using any Jquery or dependencies.

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