JSFiddle - React, Tailwind, and code Playground

HTML

<textarea id="id"></textarea>

JavaScript

(function($) {
  $.fn.setCursorPosition = function(pos) {
    if ($(this).get(0).setSelectionRange) {
      $(this).get(0).setSelectionRange(pos, pos);
    } else if ($(this).get(0).createTextRange) {
      var range = $(this).get(0).createTextRange();
      range.collapse(true);
      range.moveEnd('character', pos);
      range.moveStart('character', pos);
      range.select();
    }
  }
}(jQuery));

    $("#id").keyup(function(){
        if ($(this).val().split('').pop() !== '?') {
            $(this).val($(this).val() + "?");
            $(this).setCursorPosition( $(this).val().length - 1)
        }
    });