I want to display new-line text input taken in textfield in new-line that is as below
Hello, \\1st line
This is how i want to display, \\2nd line
such input is given to textfield. \\3rd line
I am using following code by using this code, what text i am entering in new line it not displaying at all.(not also 1st line text) This code only displaying single line text
{% for obj in post %}
<script>
var str= '{{ obj.content }}';
$(".statbox").prepend("<div class='box2'>" + str + "</div>");
</script>
{% endfor%}
if i am using following code then it displaying all new line entering text but in only single line as below
{% for obj in post %}
<div class='box2'> {{ obj.content }} </div>
{% endfor%}
and its output
Hello,\\1st line\\ This is how i not want to display, \\2nd line\\ such input is given to textfield. \\3rd line
so how can i display all new-line enterd input in new line using js code becoz i want to disply those text in prepend manner
Thnaks in adv...
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>