Too much text? Truncate it.

Again looking for something simple to fulfill a client request, and unable to find it, I wrote a little plugin to do the job.

Truncate is a jQuery plugin for shortening text in one or more content elements.

Invoking the method will limit elements’ number of initially visible words, and will add a link to show (or hide) the full text. If the number of words in any of the elements is less than or equal to the limit, no link will appear.

It will also check for sentence-completing punctuation (. ? !) at the end of the cutoff word. If none exists, it will add ellipses.

And it’s only 1K compressed!

Check out the example:

View Example

Grab it from GitHub:

Fork Me

Leave a Comment

Your email address will not be published. Required fields are marked *