JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
<input type="text" id="a">
<button type="button" id="sqrt">
sqrt()
</button>
JavaScript
$('#sqrt').click(function() {
var length = $('#a').val().length;
$('#a').val($('#a').val() + 'sqrt()');
$('#a').focus()[0].setSelectionRange(length+5, length+5);
});