Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set cursor at the end in a textarea?

Tags:

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.

like image 876
Brian Hawk Avatar asked Apr 14 '12 23:04

Brian Hawk


People also ask

How do you move the cursor to the end of a line?

Press the End key and the cursor (and position property) move to the end of the current line.

How do you move the cursor to the end of the text in a TextBox C#?

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.

How do I change the cursor position in TinyMCE editor?

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.


1 Answers

There may be many ways, e.g.

element.focus();
element.setSelectionRange(element.value.length,element.value.length);

http://jsfiddle.net/doktormolle/GSwfW/

like image 200
Dr.Molle Avatar answered Oct 10 '22 15:10

Dr.Molle