I am trying to embed text in a textbox after each line-break. Specifically, I want to add <div>
at begining of each line in the textarea and ending up with </div>
. I have tried this code but it just adds the text at the beginning and end of the value:
var arr = [document.getElementById("text1").value];
for( i=0; i<arr.length; i++ )
text2.value = '<div>' + arr[i] + '</div>';
It gives the output like:
<div>
text line 1
text line 2
text line 3
</div>
But all I want is this:
<div>text line 1</div>
<div>text line 2</div>
<div>text line 3</div>
OR