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

80
Views
How do i find where the button is clicked so that I can position something over there?

I want the popup or modal or toast to appear right where the button in clicked in react. But I was unable to find anything on this. Anything I could find was something like,it appeared in the center or the top or something predefined I guess still not right where the the button was clicked. How should approach this?

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

0

https://reactjs.org/docs/events.html#mouse-events

The MouseEvent parameter on the onClick callback contains the x and y coordinates of the click.

const handleClick = (mouseEvent) => {
    console.log(`x = ${mouseEvent.clientX}, y = ${mouseEvent.clientY}`)
}

React provides 3 different coordinates client, page, and screen the example above makes use of the client coordinates. You can read more about their differences in the MDN Web Docs

about 4 years ago · Juan Pablo Isaza Report

0

const box = document.querySelector('#box');

box.addEventListener('click', function(event) {
    console.log(`Horizontal: ${clientX}, Vertical: ${clientY}`);
    // Take Position Current onClick
});

You can set top by clientY, left by clientX from event listener

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!