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.
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.
- Why are u doing a substring(). What is the expected result? – Akhil Sekharan Commented Jul 25, 2013 at 5:52
- Please explain the issue you are having. – andrewb Commented Jul 25, 2013 at 5:53
-
2
You can use CSS ->
text-overflow:ellipsis;
– adeneo Commented Jul 25, 2013 at 5:53 - Can you give an example in "jsfiddle" – Ishan Jain Commented Jul 25, 2013 at 6:10
- 1 thnk you every one for helping – Reshma Commented Jul 26, 2013 at 7:28
3 Answers
Reset to default 5But for this you should set width
of element -
Try this CSS -
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
width: 100%;
display: inline-block;
See in jsfiddle
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;
}
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.