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

228
Views
Get coordinates of element inside dropdown

I got a dropdown list and want to show some information on hover for each element. I tried something like this, with item being the list elements and infobox being a fixed positioned div providing the information:

item.addEventListener("mouseover", (e) => {
   e.stopPropagation();
   if (e.target === e.currentTarget) {
     dropdownInformation.category_id = selectOptions.category_id[index];
     document.getElementById("infobox").style.left = e.target.getBoundingClientRect().x + "px";
     document.getElementById("infobox").style.top = e.target.getBoundingClientRect().y + "px";
     }
});

How'd I get the correct coordinates of the right border of the list entries?

Dropdown list

(Yes, I did read several other questions regarding that topic on SO)

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

0

Okay, this seems to do the trick. I needed to add / subtract the width / height of the parent element and the scrollbar.

item.addEventListener("mouseover", (e) => {
    e.stopPropagation();
    if (e.target === e.currentTarget) {
        dropdownInformation.category_id = selectOptions.category_id[index];
        e.target.style.borderLeft = "2px white solid";
        document.getElementById("infobox").style.left = 
          (e.target.getBoundingClientRect().x +
          e.target.getBoundingClientRect().width + 
          (e.target.parentElement.offsetWidth - 
          e.target.parentElement.clientWidth)) + "px";

        document.getElementById("infobox").style.top = 
          (e.target.getBoundingClientRect().y - 
          (e.target.parentElement.getBoundingClientRect().height / 2)) + "px";
    }
});
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!