$("a.newslinks").each(function(){
if ($(this).text().length > 38) {
$(this).text().substr(35); //does not work
$(this).append('...'); //works
$(this).css({ "color" : "#ff00cc" }); //works
}
});
If a link has its text longer than 38 characters, how can I trim it to 35 chars and add an elipses at the end?
substr(35)will chop 35 characters off the start of the string – not limit it to 35 chars in length.Try:
Also, this function just returns a new string – it doesn’t change the original. So you need to do