Skip to content
Advertisement

Tag: truncation

Smart way to truncate long strings

Does anyone have a more sophisticated solution/library for truncating strings with JavaScript and putting an ellipsis on the end, than the obvious one: Answer Essentially, you check the length of the given string. If it’s longer than a given length n, clip it to length n (substr or slice) and add html entity … (…) to the clipped string. Such

Ellipsis in the middle of a text (Mac style)

I need to implement ellipsis (“…”) in the middle of a text within a resizable element. Here is what it might look like. So, becomes When the element is stretched out to the width of the text, I want the ellipsis to disappear. How can this be done? Answer In the HTML, put the full value in a custom data-*

Advertisement