i-CONICA
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.
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.
ASKER
Hi, Thanks.
I've no idea how to implement this, could you provide an example?
Thanks.
I've no idea how to implement this, could you provide an example?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much.
Use : substr(0, length)
http://www.w3schools.com/jsref/jsref_substr.asp
So in your case : var myStr = myStr.substr(0,25);
Regards.