Created
November 20, 2024 02:51
-
-
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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