How to insert word break into textarea in text inserted via jquery/javascript?

Asked

Viewed 13,641 times

5

I have a textarea and would like to list some items in it one on each line.

I am already inserting the text normally in the textarea and separating the items in commas currently:

nomUgs = selUgs.join(", ");

Instead of this comma wanted to insert line break. It’s like?

1 answer

8


You can use the \n to break the line.

Example: http://jsfiddle.net/Wm9um/

For example this code separates each word into a different line:

var texto = 'Eu quero que este texto seja separado em muitas linhas!';
var linhas = texto.replace(/\s/g,'\n');
$('#testes').val(linhas);

Browser other questions tagged

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