How to do a line break with jquery?

Asked

Viewed 647 times

0

I have a textarea, and when you type the text will appear in the html image you understand? Like thisinserir a descrição da imagem aqui

I wanted to know how to make my text break there in the other div from the moment I enter a textarea.Com Jquery.

  • 2

    You can display HTML and explain the relationship between typing text, textarea and image?

  • You’ll get better answers if you give people code that they can use to reproduce the problem. This will help you a lot https://pt.meta.stackoverflow.com/questions/5483/manual-de-como-n%C3%83o-fazer-perguntas/5485#5485

  • Other essential reading https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079

1 answer

2

Use the tag pre inside the div.

<pre> - HTML | MDN is the tag used to represent pre-formatted text. A text within this element is typically displayed in a non proportional font in the same way the original text was arranged in the file. Blank spaces are kept in the text the same way it was typed.

$(function() {
    $origem=$("#origem");
    $saida=$("#saida");
    $origem.keyup(function() {
       $saida.text($origem.val());
    });
});
body { color:#ffffff}

#origem { width:250px; height:5em;}

#saida { 
    font-family: Arial Black; font-size: 14px;
}

.imagemDeFundo{
    background: url('https://thumbs.dreamstime.com/t/textura-do-grunge-do-quadro-negro-36176292.jpg') no-repeat; 
    height:400px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea id="origem"></textarea>
<div class="imagemDeFundo"><pre id="saida"></pre></div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.