Display only 10 characters of a long string?

Nasir picture Nasir · Aug 5, 2010 · Viewed 201.9k times · Source

How do I get a long text string (like a querystring) to display a maximum of 10 characters, using JQuery?

Sorry guys I'm a novice at JavaScript & JQuery :S
Any help would be greatly appreciated.

Answer

Sebs picture Sebs · Aug 5, 2010

If I understand correctly you want to limit a string to 10 characters?

var str = 'Some very long string';
if(str.length > 10) str = str.substring(0,10);

Something like that?