JSFiddle - React, Tailwind, and code Playground
HTML
<textarea name="body" rows=10 id="input" class="text">Test
Test
This text will flash
If the user presses enter and the text area is scrolled.
This will flash if user presses enter
</textarea>
JavaScript
$('#input').on("keypress", function(e) {
if (e.keyCode == 13) {
e.preventDefault();
var value = $("#input").val();
pos = $("#input").prop('selectionStart');
$("#input").focus();
$("#input").val(value.substring(0, pos) + "\nHello\n" + value.substring(pos));
this.setSelectionRange(pos + 7, pos+7);
return false;
}
});