I have a textarea and a button on a form. The textarea may already have some text in it. I would like the cursor to move to the last position in the text area when the button is clicked.
Is this possible?
xgMz's answer was best for me. You don't need to worry about the browser:
var html = $("#MyTextArea").val();
$("#MyTextArea").focus().val("").val(html);
And here's a quick jQuery extension I wrote to do this for me next time:
; (function($) {
$.fn.focusToEnd = function() {
return this.each(function() {
var v = $(this).val();
$(this).focus().val("").val(v);
});
};
})(jQuery);
Use like this:
$("#MyTextArea").focusToEnd();