Reputation: 502
var txt = 'Some texts, html tags & all values i can enter through text box';
txt= txt.substring(0,255)+'...';
Can i do this thing using css?
My problem is if txt
contains HTML tags, after doing a sub string the closing tag gets missing and it will break.
Upvotes: 1
Views: 19877
Reputation: 8171
But for this you should set width
of element -
Try this CSS -
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 100%;
display: inline-block;
Upvotes: 5
Reputation: 5428
If you're using jQuery, you can use it's text()
function.
var txt = 'Some texts, html tags & all values i can enter through text box';
txt= txt.text().substring(0,255)+'...';
That will display all non-html elements.
Upvotes: -2
Reputation: 7442
CSS will only work when you have to display the txt information on screen in some elements such as <div>
or <p>
In order to make text appear with ellipses, try the following CSS properties
p{
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
Upvotes: 1