Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!