Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda