Skip to content

Instantly share code, notes, and snippets.

@mttmzr
Last active February 1, 2022 05:23
Show Gist options
  • Save mttmzr/a1df98c8a9367e7eaa3cc7f61cd93f33 to your computer and use it in GitHub Desktop.
Save mttmzr/a1df98c8a9367e7eaa3cc7f61cd93f33 to your computer and use it in GitHub Desktop.
Simple javascript function to check if an element is truncated.
/**
* Check if an element is truncated.
*
* CSS to be used:
* .truncate {
* width: 250px;
* white-space: nowrap;
* overflow: hidden;
* text-overflow: ellipsis;
* }
*
* See http://stackoverflow.com/a/27155342/2131573
* and https://css-tricks.com/snippets/css/truncate-string-with-ellipsis/
*/
function isTruncated(el) {
return el.scrollWidth > el.clientWidth
}
@aditodkar
Copy link

How can I get width of multiple div elements whose max width is 400px? I want to perform action when 400px is hit.

@khantajuddin
Copy link

It does not work in Firefox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment