0

I add text to a div with the following jQuery code:

jQuery("div").text('some lorem ipsum');

The div has a maximum width of 400px set by css. If I enter a text which is longer than 400px and has no whitespace, the text will not get breaked down into a new line. Instead it overflows the div which I dont want. How can I solve it, that this text withouth whitespace is breaked down after 400px to a new line?

tester
  • 3,977
  • 5
  • 39
  • 59

2 Answers2

1

Use css word-break jsfiddle

div{
 word-break:break-all;
}
Anoop
  • 23,044
  • 10
  • 62
  • 76
  • sry, the other guy was faster, so i marked it as right, but yours also a solution and i gave +1 – tester Mar 17 '13 at 21:30
  • @tester. just for your info: mine is faster than other if you see time difference. but his solution is better see http://stackoverflow.com/questions/1795109/what-is-the-difference-between-word-break-break-all-versus-word-wrap-break – Anoop Mar 17 '13 at 21:34
0

You can do this in CSS with the word-wrap property:

div {
    word-wrap: break-word
}
antoyo
  • 11,097
  • 7
  • 51
  • 82