0

I have a div, which has the css to truncate the text for certain width. The text gets truncated with ellipsis. However the inner text is the same. For the testing purpose I would want to read the truncated ellipsis text. Can I get the truncated ellipsis text with js?

@media (max-width: 1129px) {
    #mydiv {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100px;
        display: inline-block;
    }
}

1 Answer 1

1

There's no easy way to do this, you'd have to do it manually with JavaScript by:

  1. Calculating the viewable width of the div
  2. Take your text and remove any characters that would be outside of this width

It's also been discussed here Get clamped (with ellipsis) textContent from textNode

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.