chrigu
chrigu

Reputation: 55

How to make text nodes with new lines in it without using "style=white-space: pre"?

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?

Upvotes: 3

Views: 208

Answers (1)

Ramon Balthazar
Ramon Balthazar

Reputation: 4260

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

Upvotes: 3

Related Questions