How to display text from textarea.value in browser with line breaks entered?

  • 0
    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

  • 3 Answers
  • 0
    Just apply the white-space: pre-wrap;
    property to the div block where the CSS text is inserted
    Logan Erickson

  • 0

    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.


  • 0

    The simplest option

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!