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
html
Some very very very very very very very very very very very long string
javascript (on doc ready)
var longText = $('#longText');
longText.text(longText.text().substr(0, 10));
If you have multiple words in the text, and want each to be limited to at most 10 chars, you could do:
var longText = $('#longText');
var text = longText.text();
var regex = /\w{11}\w*/, match;
while(match = regex.exec(text)) {
text = text.replace(match[0], match[0].substr(0, 10));
}
longText.text(text);