document.getElementById('area').onkeyup=keydown;
function keydown (event) {
if (event.target.id=='area' && event.which==13) {
document.getElementById('arsh').innerHTML+="\n";
}
}
Arsh is the ID of my paragraph where i want to add the new line why is this not working can anyone help me ?I just want to add a new line when Enter is pressed in the textarea (ID area) to my Paragraph (ID arsh).
here is the HTML
<textarea ID="area" class="in">
Message
</textarea>
<br />
<br />
<p ID="tiesh" class="sh">
</p>
<br />
<br />
<p ID="arsh" class="sh">
</p>
<br />
</div>
I am basically trying to do it like here in stackoverflow when you press enter in the textarea down the paragraph jumps down a line also.
Using CSS, give #arsh
(or any other elements that you want to render new lines) this attribute.
white-space: pre-wrap;
document.getElementById('arsh').innerHTML=document.getElementById("area").value.replace(/\n/g,'<br />')
this will do the job
The newline character (\n) do not render as new lines on the screen. You probably need to add an HTML break instead:
document.getElementById('arsh').innerHTML+="<br />";
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