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

181
Views
Find mouse event target for position in JavaScript

I don't actually want to trigger an event. I just want to find out programmatically which element will handle the onmousedown if the mouse is clicked at position x/y.

The purpose is to then add an interceptor to that element which point-event: none

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

0

// without pointer-events: none;
const element = document.elementFromPoint(mouseX, mouseY);
function elementsFromPoint(x, y) { // pointer-events: none;
    const elements = document.body.getElementsByTagName("*");
    var elementsList = Array.prototype.slice.call(elements);

    var results = []
    elementsList.forEach(element => {
        var rect = element.getBoundingClientRect();

        if (rect.left < x && x < rect.right && rect.top < y && y < rect.bottom) {
            results.push(element)
        }
    });
    return results;
}
window.addEventListener('load', () => {
    const textarea = document.querySelector('#text')
    document.addEventListener('click', (e) => {

        const element = elementsFromPoint(e.clientX, e.clientY);
        console.log(element)
    })

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