I'm trying to retrieve the length of a div and cut it off once it reaches the the last full word before 250 characters. I also need to add "...". I've seen several posts related to this but nothing seems to be working for me. I haven't gotten any errors in the console so I know my function isn't right.
function short(length) {
var s = document.getElementsByTagName('.message'),
len = s.length;
for (var i = 0; i < len; i++) {
var g = s[i].innerHTML,
x = '...',
leng = length- 3,
html = g.substring(0, leng) + "",
allHTML = html + x;
s[i].innerHTML = allHTML;
}
}
short(250);