1
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.

6
  • Why are u doing a substring(). What is the expected result? Commented Jul 25, 2013 at 5:52
  • Please explain the issue you are having. Commented Jul 25, 2013 at 5:53
  • 2
    You can use CSS -> text-overflow:ellipsis; Commented Jul 25, 2013 at 5:53
  • Can you give an example in "jsfiddle" Commented Jul 25, 2013 at 6:10
  • 1
    thnk you every one for helping Commented Jul 26, 2013 at 7:28

3 Answers 3

5

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;

See in jsfiddle

Sign up to request clarification or add additional context in comments.

Comments

1

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;
}

Comments

-2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.