How to add new line breaks in textarea using Javascript ?

Would you please give me advice how to dynamically insert a new lines in textarea ? I tried to add <br /> and later \n but it doesn't work.
posted on 21.06.2019 at 19:23
0pnshow more
onefiveonefive
Hi,

To dynamically add new line break into textarea with javascript, you can use escaped \n or \r\n:

\\n

\\r\\n

Code could look like:

document.getElementById('text').value='Hello\\r\\n\\r\\nThe content...';
posted on 24.06.2019 at 19:02
0pnshow more
TimTim
share on facebookshare on twitter
2021 AnswerTabsTermsContact us