Skip to content

Instantly share code, notes, and snippets.

@trinhvanminh
Created November 20, 2024 02:51
Show Gist options
  • Save trinhvanminh/581440adf730f629fd33400fb03a9760 to your computer and use it in GitHub Desktop.
Save trinhvanminh/581440adf730f629fd33400fb03a9760 to your computer and use it in GitHub Desktop.
Detect CSS Ellipsis in JavaScript and add a title. https://jsfiddle.net/tzi/qtqnqomL/
// https://jsfiddle.net/tzi/qtqnqomL/
function isEllipsisActive(element) {
return element.offsetWidth < element.scrollWidth;
}
Array.from(document.querySelectorAll('.ellipsis'))
.forEach(element => {
if (isEllipsisActive(element)) {
element.title = element.innerText;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment