I am pulling from a JSON feed and I just want to display a maximum of 10 characters of the string and then do a ... afterwards. How do I do that with JQuery?
You can use CSS to set up an ellipsis:
.myparagraph {
white-space: nowrap;
width: 10em;
overflow: hidden;
text-overflow: ellipsis;
}
Then there's no need for any jQuery or other coding.
References:
(note that first link - Quirksmode.org is an excellent resource generally for CSS and Javascript stuff)
I haven't checked this for off by one errors, so you might have to adjust for poor indexing.
var txt = SomeStringFromFeed;
if(txt.length > 10)
{
txt = txt.substr(0,10) + "...";
}
return txt;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With