2
How to take the value of textarea
separated by line and add a div
?
I would like to write a text on textarea
separated by lines and sent to the other textarea by adding a div
with the attribute class
with increasing numbers on each row as in the examples below:
My code (which only works with 1 line):
function text(){
var txt = document.getElementById('txt')
var ext = document.getElementById('ext')
ext.value = "<div class='classe1'>" +txt.value+ "</div>"
}
<textarea id="txt" oninput="text()"></textarea><br><textarea id="ext"></textarea>
Example of where I’m going with this:
<textarea style='height:60px;'>Texto 1
Texto 2
Texto 3</textarea><br>
<textarea id="txt" style='height:60px;'><div class="class1">Texto 1</div>
<div class="class2">Texto 2</div>
<div class="class3">Texto 3</div></textarea>
Explain further your doubt, got a little confused.
– ElvisP
It’s not related to the answer, but
<div>
does not have the attributename
(at least in valid HTML). What you need thename
? You could useid
orclass
if only for HTML manipulation or<input type="hidden">
if to send the data in separate inputs.– fernandosavio
It’s just an example I could simply change to
class
– Mark