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.
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.
Although this won't limit the string to exactly 10 characters, why not let the browser do the work for you with CSS:
and then for the table cell that contains the string add the above class and set the maximum permitted width. The result should end up looking better than anything done based on measuring the string length.
And here's a jQuery example:
HTML text field:
jQuery code to limit its size:
As an example, you could use the jQuery code above to restrict the user from entering more than 10 characters while he's typing; the following code snippet does exactly this:
Update: The above code snippet was only used to show an example usage.
The following code snippet will handle you issue with the DIV element:
Please note that I'm using
text
instead ofval
in this case, since theval
method doesn't seem to work with the DIV element.If I understand correctly you want to limit a string to 10 characters?
Something like that?
Show this "long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text long text "
to
long text long text long ...
What you should also do when you truncate the string to ten characters is add the actual html ellipses entity:
…
, rather than three periods.Result variable contains "I am too l..."