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

287
Views
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 answers
Answer question

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