Is there a way to set the cursor at the end in a textarea
element? I'm using Firefox 3.6 and I don't need it to work in IE or Chrome. It seems all the related answers in here use onfocus()
event, which seems to be useless because when user clicks on anywhere within the textarea
element Firefox sets cursor position to there. I have a long text to display in a textarea
so that it displays the last portion (making it easier to add something at the end).
No frameworks or libraries.
Press the End key and the cursor (and position property) move to the end of the current line.
To position the cursor at the end of the contents of a TextBox control, call the Select method and specify the selection start position equal to the length of the text content, and a selection length of 0.
Setting the cursor position You can also hold down shift and then move the cursor with the arrow keys on the keyboard to select content. It has the same effect. The TinyMCE bookmarks this location with the Bookmark Manager API, and then loads the selected location later.
There may be many ways, e.g.
element.focus();
element.setSelectionRange(element.value.length,element.value.length);
http://jsfiddle.net/doktormolle/GSwfW/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With