JSFiddle - React, Tailwind, and code Playground

by Kiran Reddy

HTML

<textarea class="texty"></textarea>

CSS

.texty {
    width: 400px;
    height: 300px;
}

JavaScript

$(document).ready(function() {
    $(".texty").bind("keyup", function(e) {
        if (e.which == 13) {
            var caretPos = $('.texty')[0].selectionStart;
            var textAreaTxt = $(this).val();
            var txtToAdd = "I am ";
            $(this).val(textAreaTxt.substring(0, caretPos) + txtToAdd + textAreaTxt.substring(caretPos) );
        }
    });
});