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

281
Visualizações
Get and keep only original target of mousedown event?

I want to get and keep only the original target element of a mousedown event -- but as the user holds the mouse down, the event.target changes depending on what's under the pointer.

There is a property event.originalTarget which does exactly what I want, but it's only supported by Firefox (reference: https://developer.mozilla.org/en-US/docs/Web/API/Event/originalTarget ).

How can I replicate this behavior using standard event.target?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Figured it out: you need to create flags outside the event listener.

let el = false
let mousedown = false;

document.addEventListener('mousedown', ev => {
        if (!mousedown) {
            el = ev.target;
            mousedown = true;
        }
    });

document.addEventListener('mouseup', ev => {
        mousedown = false;
        el = false;
    });

So el will be set as the original target for the duration of the mousedown, but on mouseup, it's reset back to nothing.

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