How do you make line breaks in an HTML text box as a result of line breaks?

I have HTML <textarea>that I want to do when the user clicks on an input in a text field, it causes a line to appear when the line is stored in a variable and printed on the page.

How should I do it? I have seen this before, but I'm not sure how to do it.

+3
source share
3 answers

When you read the contents of a text field, simply do the following:

var text = document.getElementById(textAreaId).value.replace("\n","<br/>");

That way, when you use variable text, it will be able to break lines in html.

+2
source

white-space pre. . : http://www.w3schools.com/CSS/pr_text_white-space.asp

<p style="white-space: pre;">Your text with newlines goes here.</p>

<pre>, HTML, white-space: pre; , .

<br /> . , HTML .

+1

, HTML, <br> <pre>.

<pre> .

pre ( Courier), , .

0

Source: https://habr.com/ru/post/1771368/


All Articles