I am storing content in the database, for example:
Hello
This
is
Text
and when I pass that to a textarea, it stays with the new line breaks. But if I pass that text to a div with content editable, it would stay like this:
Hello This is Text
How can I fix this problem?
4 Answers
Set a style on the div: white-space: pre or white-space: pre-wrap
Example:
To add some info on @Explosion Pills correct answer and extract some info from MDN:
The CSS white-space attribute is there to help:
pre:
white-space: pre
Sequences of white space are preserved. Lines are only broken at newline characters in the source and at
<br>elements.
This might result in unwanted horizontal scrollbars as shown in the example!