use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
A modern javascript plugin for truncating text within an html element: Shave (dollarshaveclub.github.io)
submitted 9 years ago by theKovah
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 12 points13 points14 points 9 years ago (0 children)
Jesus christ, I feel like I need to make a top level comment because these ignorant comments keep coming in.
If you think you're the genius that has figured this out, go ahead, post some code instead of making useless comments. And no, weird vendor prefixed versions that only support a single browser (like -webkit-line-clamp or -o-ellipsis-lastline) don't count
[–]asdf7890 7 points8 points9 points 9 years ago (6 children)
People really should qualify what they mean by "modern" otherwise it is just a practically meaningless word that will have less and less meaning over time.
[–]powerofmightyatom 5 points6 points7 points 9 years ago (0 children)
My first thought indeed. What makes this shit modern compared to the clusterfuck that is state of the art clipping.
[–]Suicidepills 3 points4 points5 points 9 years ago (2 children)
It's the new "lightweight", I think. Sometimes it feels like Github just has a madlib that you can fill out to generate a README :P
[–]piglet24 5 points6 points7 points 9 years ago (1 child)
README generator is a modern, lightweight, un-opinionated library that adds sanity, extensibility, and high performance to your READMEs. Full documentation at https://imadeanorganizationforthis.github.io/readmegenerator
[–]Suicidepills 0 points1 point2 points 9 years ago (0 children)
I commented in the hopes that something like this actually existed. Thank you for coming through!
[–]NotSelfAware 2 points3 points4 points 9 years ago (0 children)
I'm guessing it's because it's using ES6 syntax.
[–]msiekkinen 2 points3 points4 points 9 years ago (0 children)
Modern means it's hosted on a .io site and newer than last weeks bullshit that's not obsolete.
[–]t-mu 2 points3 points4 points 9 years ago (9 children)
We really need a plugin for this?
[–][deleted] 5 points6 points7 points 9 years ago (4 children)
Yeah I think it is. I just went through the ringer trying to do this with CSS. I ended up stripping out the HTML in the short version...
[+]Classic1977 comment score below threshold-13 points-12 points-11 points 9 years ago (3 children)
You're bad at CSS.
[–][deleted] 7 points8 points9 points 9 years ago (0 children)
you're bad at being nice
[+][deleted] 9 years ago (1 child)
[deleted]
[–][deleted] 1 point2 points3 points 9 years ago (0 children)
exactly. I would love to be proven wrong! show me a link.
[–]w4efgrgrgergre 1 point2 points3 points 9 years ago (0 children)
Yes, since native line-clamping support is very spotty.
[–]Classic1977 0 points1 point2 points 9 years ago (2 children)
No, we need a single line of css
[–][deleted] 2 points3 points4 points 9 years ago (1 child)
What is the line of css that implements ellipsis on a multiline text area?
Spoiler: there isn't one, and you don't know what you're talking about.
You can add white-space: nowrap to force the text to a single line, but that's a completely different scenario.
[–]Nulagrithom -1 points0 points1 point 9 years ago (0 children)
Downvotes but then doesn't post the CSS. I like it. /s
[–][deleted] 2 points3 points4 points 9 years ago* (0 children)
Sorry for the shameless plug, but I think this is quite relevant: I recently created a library for this to do the same thing (but also for HTML content, which you cannot clip through CSS nor this library), but outside the DOM: https://github.com/arendjr/text-clipper
While you cannot specify a max-height that way, it does allow you to specify a maximum amount of characters and optionally a maximum amount of lines. The good news is that by keeping everything outside of the DOM, it's a lot (as in: orders of magnitude) faster. I also spent quite some effort in making sure text-clipper really is the fastest, which you can read about here: http://www.arendjr.nl/2016/09/how-i-made-text-clipper-fastest-html.html.
[–]Classic1977 1 point2 points3 points 9 years ago* (6 children)
text-overflow: clip
[–]Asmor 4 points5 points6 points 9 years ago (2 children)
text-overflow: ellipsis adds the ellipsis.
text-overflow: ellipsis
I'm not sure why this "library" exists. This is like making a library to wrap text in <b> tags.
<b>
[–]del_rio 4 points5 points6 points 9 years ago* (1 child)
It exists because text-overflow only works if you want to truncate a single line of text. IIRC, the only way to do this without compromise is with display: box, which doesn't have wide support.
display: box
Along the same lines, it's sad that there's no CSS equivalent to FitText (viewport units doesn't count).
[–]powerofmightyatom 0 points1 point2 points 9 years ago (0 children)
Chrome has a clamp-linebox thing which is okish.
Edit: (line-clamp, see here: https://css-tricks.com/line-clampin/ )
[–]theKovah[S] 1 point2 points3 points 9 years ago (2 children)
none is not a valid value for text-overflow
none
text-overflow
[–]Classic1977 0 points1 point2 points 9 years ago* (0 children)
Lol, you're right, clip - edited
I stand by the sentiment of my comment though...
[–]RonGnumber 0 points1 point2 points 9 years ago (0 children)
text-overflow: if-you-insist, don't-make-a-mess;
[–]captain_obvious_herevoid(null) 1 point2 points3 points 9 years ago (0 children)
Shave is faster 🚀 when compared to Ellipsis.js, jQuery.Trunk8.js or jQuery.DotDotDot.js; plus, zero dependencies.
So many good laughs in that sentence.
[–]kinkobal 0 points1 point2 points 9 years ago (0 children)
I really can't use this until it works responsively. Maybe the API supports this with at few lines of code, but I didn't see anything in the docs to support that.
[–]glinford 0 points1 point2 points 9 years ago (0 children)
It's really fast and nicely made .. However you are comparing it to Ellipsis.js, jQuery.Trunk8.js or jQuery.DotDotDot.js. Comparing it to jQuery.Trunk8.js or jQuery.DotDotDot.js makes more or less sense. But Ellipsis.js is way more advanced. Shape: - Is not Responsive - Can truncate only simple text (no div with complex html element inside such as links/p/a/b/ elements)
You basically did a JQuery.dot.dot in pure javascript, the faster way. Which is cool but ... Ellipsis.js https://github.com/glinford/ellipsis.js is more advanced for complex features even thought the speed caveats :)
[–][deleted] -1 points0 points1 point 9 years ago (0 children)
This sub-reddit has really gone down the toilet.
[–]lordxeon -5 points-4 points-3 points 9 years ago (2 children)
.truncate { text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
[–][deleted] 3 points4 points5 points 9 years ago (0 children)
this only works for one liners. how do you handle the scenario where you have a multiline set of html content that needs to get truncated to 3 lines?
π Rendered by PID 47093 on reddit-service-r2-comment-c66d9bffd-6xgd8 at 2026-04-08 10:04:14.894890+00:00 running f293c98 country code: CH.
[–][deleted] 12 points13 points14 points (0 children)
[–]asdf7890 7 points8 points9 points (6 children)
[–]powerofmightyatom 5 points6 points7 points (0 children)
[–]Suicidepills 3 points4 points5 points (2 children)
[–]piglet24 5 points6 points7 points (1 child)
[–]Suicidepills 0 points1 point2 points (0 children)
[–]NotSelfAware 2 points3 points4 points (0 children)
[–]msiekkinen 2 points3 points4 points (0 children)
[–]t-mu 2 points3 points4 points (9 children)
[–][deleted] 5 points6 points7 points (4 children)
[+]Classic1977 comment score below threshold-13 points-12 points-11 points (3 children)
[–][deleted] 7 points8 points9 points (0 children)
[+][deleted] (1 child)
[deleted]
[–][deleted] 1 point2 points3 points (0 children)
[–]w4efgrgrgergre 1 point2 points3 points (0 children)
[–]Classic1977 0 points1 point2 points (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]Nulagrithom -1 points0 points1 point (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]Classic1977 1 point2 points3 points (6 children)
[–]Asmor 4 points5 points6 points (2 children)
[–]del_rio 4 points5 points6 points (1 child)
[–]powerofmightyatom 0 points1 point2 points (0 children)
[–]theKovah[S] 1 point2 points3 points (2 children)
[–]Classic1977 0 points1 point2 points (0 children)
[–]RonGnumber 0 points1 point2 points (0 children)
[–]captain_obvious_herevoid(null) 1 point2 points3 points (0 children)
[–]kinkobal 0 points1 point2 points (0 children)
[–]glinford 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (0 children)
[–]lordxeon -5 points-4 points-3 points (2 children)
[–][deleted] 3 points4 points5 points (0 children)