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

261
Visualizações
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 Respostas
Responde à pergunta

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