0

In my JavaScript I download a textfile with ajax. This textfile contains multiple word on multiple lines. However when I put the retrieved text in a <p> all text is displayed single lined. Via Alert() or console.log I do get the newlines. How can i get <p> or another element to display the newlines? My question is pretty basic, so I don't think my code is necessary to upload. If it is, just ask.

Evgeny Samsonov
  • 2,730
  • 4
  • 19
  • 28
Rik Smits
  • 63
  • 9
  • 2
    Possible duplicate of [Render a string in HTML and preserve spaces and newlines](http://stackoverflow.com/questions/9492249/render-a-string-in-html-and-preserve-spaces-and-newlines) – James Thorpe Oct 22 '15 at 11:44

1 Answers1

1

\n is ignored in HTML by default. It doesn't work like <br>.

Anyway you can try with adding following CSS to your <p>

white-space: pre-wrap;
hsz
  • 148,279
  • 62
  • 259
  • 315