Sometimes, we want to add line breaks to an HTML textarea with JavaScript.
In this article, we’ll look at how to add line breaks to an HTML textarea with JavaScript.
How to add line breaks to an HTML textarea with JavaScript?
To add line breaks to an HTML textarea with JavaScript, we can add 'rn'
to the string.
For instance, we write
const txtArea = document.getElementById("txt");
txtArea.value += text + "rn";
to select the text area with getElementById
.
And then we append text + "rn"
to the value
property.
"rn"
adds the line breaks.
Conclusion
To add line breaks to an HTML textarea with JavaScript, we can add 'rn'
to the string.