Adds text into a text area at the user's cursor position or replaces selected text. (https://stackoverflow.com/questions/11076975/insert-text-into-textarea-at-cursor-position-javascript)
$( 'input[type=button]' ).on('click', function(){
var cursorPosStart = $('#text').prop('selectionStart');
var cursorPosEnd = $('#text').prop('selectionEnd');
var v = $('#text').val();
var textBefore = v.substring(0, cursorPosStart );
var textAfter = v.substring( cursorPosEnd, v.length );
$('#text').val( textBefore+ $(this).val() +textAfter );
});