Skip to content
Advertisement

getting textarea value with newlines javascript

I have an HTML textarea and when data entered, and when submitted a js function takes values form textarea and puts them into a paragraph. but there is newline between textarea values and when the function takes those values it puts them without newlines in the paragraph. Is there any way to make newlines even after submitting?

JavaScript

Advertisement

Answer

Because newline in HTML is <br />. You should split the strings by newlines which can be parsed with regex /r?n/gm. using g for global flag and m for multi lines.

JavaScript

full example

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement