How to wrap the text starting from the 50th character?

Hello!

There is a script that truncates the text before the gap from the 50-th character
Here it is on jsfiddle

Now, please tell me how to alter this script, so it does not cut off the text after 50 characters, and wrapped the text after the 50th character in a span tag (so it can be hide and unhide by adding a class

Or how to modify this script just for the folding / unfolding of the text?

For earlier thanks!
March 23rd 20 at 19:31
1 answer
March 23rd 20 at 19:33
Solution
So ?
Cool!)

and is it still possible to do it on click and add an ellipsis in front of the class? - Larue22 commented on March 23rd 20 at 19:36
@Larue22, so it wrote already...

var desc_short = function () {
 jQuery("p.short").text(function(i, text) {
 if (text.length >= 30) {
 var textTmp = text.substring(0, 50);
 var lastIndex = textTmp.lastIndexOf(" "); // position of last space character

 text = text.substring(0, lastIndex) + '<span class="wrap">...'+text.substring(lastIndex, text.length-1)+'</span>'; // cut to the last word
}
jQuery(this).html(text);
});
};

$('my-button').click(function() {
desc_short();
});
- elias_Vandervort commented on March 23rd 20 at 19:39
@elias_Vandervort, Almost, I just need one knopki how to crop and expand the text - Larue22 commented on March 23rd 20 at 19:42
First click - wrap in the class + the ellipses, and the second canceling the first operation cycle - Larue22 commented on March 23rd 20 at 19:45
@Larue22, That's right ? - geovany_Bartoletti commented on March 23rd 20 at 19:48
@geovany_Bartoletti, Generous thank you - this is exactly what I need!! - Larue22 commented on March 23rd 20 at 19:51

Find more questions by tags jQueryJavaScript