How to display text from textarea.value in browser with line breaks entered?
-
Hello comrades. The page has a form with a textarea inside, and a container for rendering messages "sent" from this textarea. Line breaks are available in the textarea (press Enter / Shift + Enter - the cursor will move to a new line and all gaps will be displayed inside the textare). But when these messages are rendered to the page, all hyphenation disappears, and the content is displayed on one line. How to preserve all line breaks in general so that they appear on the page in the container as in the textarea?
Does it work here interestingly?
Or not? (It puts a maximum of 2 enter, I sizzled much more, but I need everyone to stay. Well, or at least as here, if possible)JavaScript Anonymous, Nov 2, 2019 -
Just apply the white-space: pre-wrap;
property to the div block where the CSS text is inserted
htmlbook.com/css/white-spaceLogan Erickson -
https://codepen.io/5h4dy_s/pen/ZEOMBoX
Php has a function nl2br that can add br tags
There is no such function in js, but there is a custom function, regex, that does almost the same thing.
SourceAnonymous
3 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!