본문 바로가기
✘✘✘ Javascript

How to detect text overflow ellipsis?

by PrettyLog 2023. 1. 9.

Search:: how to check if html element is in ellipsis

HTML text-overflow ellipsis detection

Try this JS function, passing the span element as argument:

function isEllipsisActive(e) {
     return (e.offsetWidth < e.scrollWidth);
}

@NicolasS.Xu I believe if the element is a span, you might get zeros in these properties. So one solution is to wrap the span in a div which has overflow: hidden and then check div properties instead. – Groo Oct 4, 2022 at 12:30

댓글