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

253
Vistas
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 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