Hulk
Hulk

Reputation: 34160

How to wrap up HTML contents?

If an HTML contains say:

<div>1222222222222234c dssdsdf sdfsdfsdf</div>

How to wrap up the contents limiting to 10 characters and maybe after that we show (12222222..) two dots.

Upvotes: 0

Views: 256

Answers (5)

Anil Namde
Anil Namde

Reputation: 6608

aaaaaaaaaa<wbr/>cccccccccc

Thought not on the same lines but is one nice thing to know, this wraps the text if and only if the text is not getting fit in space. Handy for using with the messages.

Upvotes: 0

GeekTantra
GeekTantra

Reputation: 12081

Using jQuery we can do it like this

$(function(){
  $('div').each(function(){
    if($(this).text().length > 10) {
      var text = $(this).text();
      text = text.substr(0,10);
      $(this).text(text+"...");
    }
  })
})

Upvotes: 2

Alex Sexton
Alex Sexton

Reputation: 10451

Since text-overflow: ellipsis is only "Supported by IE7-, Safari and Konqueror" - you'll probably need a javascript solution:

This is a well written one:

http://tpgblog.com/2009/12/21/threedots-the-jquery-ellipsis-plugin/

Upvotes: 2

twodayslate
twodayslate

Reputation: 2833

This should be what you want. More

Upvotes: 1

rahul
rahul

Reputation: 187030

You can use

text-overflow: ellipsis

But for a cross browser solution you will have to split the string and then append . after your desired length.

Upvotes: 2

Related Questions