I know this question is similar to THIS so apologies if considered a duplicate.
The result I'm trying to achieve is to check divs with a class of gallery-info
$('.gallery-info').each(function() {
});
I set up a condition to return a substring if the character count of each div is greater than 140 characters. (Twitter)
$('.gallery-info').each(function() {
var descLength = 140;
var str = $(this).text();
var patt = new RegExp(/[,;.:!()&\s$]/g);
if (str.length > descLength) {
$(this).text(str.substr(0, descLength) + "...");
}
});
IF
The last character of the substring matches the patt var. Return substring -1 and concat "..."
ELSE
Return substring and concat "..."
I've been having a brain fart on this and I believe I can achieve this in Vanilla JS with str.replace() and str.charAt() but I need to do this in jQuery.