tags:

views:

42

answers:

2

hey guys, why is this not working?

$("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 i wanna trim it to 35 chars and add … at the end!

what am i doin wrong?

+1  A: 

substr(35) will chop 35 characters off the start of the string - not limit it to 35 chars in length.

Try:

.substr(0, 35)

Also, this function just returns a new string - it doesn't change the original. So you need to do

$(this).text($(this).text().substr(0, 35)); 
sje397
+1  A: 

Try:

$(this).text($(this).text().substr(0, 35)); 
Kelsey