Reshma
Reshma

Reputation: 502

substring a text with html tags using css break word or something?

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

Answers (3)

Ishan Jain
Ishan Jain

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;

See in jsfiddle

Upvotes: 5

Chad
Chad

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

U.P
U.P

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

Related Questions