I would like to start a textarea with inside a text that starts some line under the first line. Doing something like:
var myText = '\r \r \r HELLO';
doesn't work: HELLO is written on the first line, while
var myText = 'HELLO \r \r \r HELLO2';
puts correctly HELLO2 after HELLO. This means that \r
is correct, but it doesn't work at the beginning of the textarea.
Any suggestions?
To add line breaks to a textarea, use the addition (+) operator and add the \r\n string at the place where you want to add a line break, e.g. 'line one' + '\r\n' + 'line two' . The combination of the \r and \n characters is used as a newline character.
To preserve line breaks when getting text from a textarea with JavaScript, we can replace whitespace characters with '<br>\n' .
Just put the output text between <pre></pre> tags, that will preserve the line breaks.
Don't use \r, use \n
Example:
var myText = '\n \n \n HELLO';
Try inserting
into the text area.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With