Link to home
Start Free TrialLog in
Avatar of i-CONICA
i-CONICAFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Javascript truncate string at 25 characters?

Hi,

I need to truncate a link's text if it's longer than 25 characters, it needs to be a simple javascript solution.
Server side, I've wrapped the link's anchor text in a <span id="truncate"> if it's longer than 25 characters, so the javascript can do the rest.
But what JS can I use for this? I've tried a few things I've found by Googling, but they seem over complex and none worked.

Thanks.
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Hello i-CONICA,

Use : substr(0, length)

http://www.w3schools.com/jsref/jsref_substr.asp

So in your case : var myStr = myStr.substr(0,25);

Regards.
Avatar of i-CONICA

ASKER

Hi, Thanks.

I've no idea how to implement this, could you provide an example?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Zyloch
Zyloch
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much.