3

I'm trying to get a textnode with new lines in it (my text contains \n and x0a). I found the way to do this, using white-space: pre, and it works, but the problem is that the content doesn't fit to the parent div, I got the new lines in the text, but when the line is long, it goes beyond the window.

This is the code:

var textdata = document.createTextNode(text_with_multiples_lines);
PanelBody.style = "white-space: pre;"
PanelBody.appendChild(textdata);

Screenshot

Somebody know how to make new lines inside a textnode without exceeding the window size?

JonathanDavidArndt
  • 2,518
  • 13
  • 37
  • 49
chrigu
  • 55
  • 7

1 Answers1

3

Set white-space to pre-wrap instead.

This also enables text lines to break as needed to fill the element box :)

More on that: MDN - white-space

Ramon Balthazar
  • 3,907
  • 3
  • 25
  • 34