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

269
Views
How to implement text-overflow: ellipsis with JavaScript?

In CSS it is easy to truncate text with ... at the end.

.elem {
  width: 100px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis
}

Unfortunately I can't use text-overflow: ellipsis in CSS because Safari shows a browser-native tooltip whenever text-overflow: ellipsis is applied and I want to show my own custom tooltip.

I know I can detect if the text is overflowing with:

elem.scrollWidth > elem.getBoundingClientRect().width

What to do from there I can't comprehend. How do I determine which characters are within view so I can grab the last three characters and turn them into full stop dots?

about 4 years ago · Santiago Trujillo
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!