[Answered ]-How to display new line input text in new line?

2👍

The issue is because HTML doesn’t respect whitespace, unless within certain elements.

To achieve what you require you can replace the line breaks in the string with <br /> tags, like this:

var str = `Hello,
  This is how i want to display,
  such input is given to textfield.`;
$(".statbox").prepend('<div class="box2">' + str.replace(/\n/g, '<br />') + '</div>');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="statbox"></div>

Leave a comment