Json result for html (Newline)

If I set the next line in a div, how can I make the new line work in HTML?

{
"s": "Phrase1. \ n \ nPhrase2"
}

Thank.

+3
source share
3 answers
foo.innerHTML = myObj.s.replace(/\n/g,"<br>");
+4
source

Trim pre-formatted text into <pre> tags:

<pre>{ "s":"Phrase1.\n\nPhrase2" }</pre>

Shows how:

{"s": "Phrase1.

Phrase2 "}

Edit: Another option is to set the style or class of the div like the pre tag:

<div style="whitespace:pre"/>
+3
source
{"s", "phrase1.<br /><br />"phrase2"}
+2
source

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


All Articles