Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
how to display new line input text in new line?

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...

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

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>

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda