I'm trying to append a br
tag after a user click enter in a textarea field.
This is what I'm trying to do:
if (e.keyCode == 13)
{
$('.myTextarea').replace('\n', "<br />");
}
Can anyone tell me what I'm doing wrong?
I'm trying to append a br
tag after a user click enter in a textarea field.
This is what I'm trying to do:
if (e.keyCode == 13)
{
$('.myTextarea').replace('\n', "<br />");
}
Can anyone tell me what I'm doing wrong?
You should get value in the textarea. See the val document http://api.jquery.com/val/.
Try this,
if (e.keyCode == 13)
{
$('.myTextarea').val(function(i, v) {
return v.replace('\n', '<br/>');
}
}
](https://stackoverflow.com/questions/5999792/new-line-in-textarea-to-be-converted-to-br) – Zak Apr 17 '18 at 22:21