Textarea tags

Insert a new text or a input value into a textarea at the cursor position using jquery

HTML

<form>
    <textarea id="text1" cols="40" rows="3"></textarea>
    <textarea id="text2" cols="40" rows="3"></textarea>
    <br>
    <input type="button" value="one" />
    <input type="button" value="two" />
    <input type="button" value="three" />
</form>

JavaScript

$( 'input[type=button]' ).on('click', function(){
            var cursorPos = $('#text1').prop('selectionStart');
            var v = $('#text1').val();
            var textBefore = v.substring(0,  cursorPos );
            var textAfter  = v.substring( cursorPos, v.length );
            $('#text1').val( textBefore+ $(this).val() +textAfter );
        });