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

259
Views
HTML/JAVASCRIPT ondragleave fired when moving between child objects

I have a problem with the behaviour of the javascript 'ondragleave' that is fired between child elements.

See the example with some simple code.

The problem is that the records would not stay red between the two TD elements, although the mouse is still dragging in the TR record.

There are some answers that include counters, but non of them seems to make is possible to work

function enter(ev, recordid) {
  document.getElementById(recordid).style.backgroundColor = '#AA0000';
}

function leave(ev, recordid) {
  document.getElementById(recordid).style.backgroundColor = '';
}
<p draggable="true" id="dragtarget">Drag me!</p>

<table width=100% style='border-spacing: 30px;'>
  <tr id='record1' ondragenter='enter(event, this.id);' ondragleave='leave(event, this.id);'>
    <td>Record 1-1</td>
    <td>Record 1-2</td>
    <td>Record 1-3</td>
    <td>Record 1-4</td>
  </tr>

  <tr id='record2' ondragenter='enter(event, this.id);' ondragleave='leave(event, this.id);'>
    <td>Record 2-1</td>
    <td>Record 3-2</td>
    <td>Record 4-3</td>
    <td>Record 5-4</td>
  </tr>
</table>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Assuming this is your issue:

problem is that the records would not stay red between the two TD elements

This can be solved with CSS & has nothing to do with ondragleave:

function enter(ev, recordid) {
  document.getElementById(recordid).style.backgroundColor = '#AA0000';
}

function leave(ev, recordid) {
  document.getElementById(recordid).style.backgroundColor = '';
}
<style>
  td { padding: 0px; }
  table { width: 100%; border-spacing: 0px; }
</style>

<p draggable="true" id="dragtarget">Drag me!</p>

<table>
  <tr id='record1' ondragenter='enter(event, this.id);' ondragleave='leave(event, this.id);'>
    <td>Record 1-1</td>
    <td>Record 1-2</td>
    <td>Record 1-3</td>
    <td>Record 1-4</td>
  </tr>

  <tr id='record2' ondragenter='enter(event, this.id);' ondragleave='leave(event, this.id);'>
    <td>Record 2-1</td>
    <td>Record 3-2</td>
    <td>Record 4-3</td>
    <td>Record 5-4</td>
  </tr>
</table>

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