Javascript – IE-10 Cursor position when set focus on textbox using jquery

internet-explorer-10javascriptjquery

I have a problem in IE -10(window -7 SP-1) when set focus on a text box. my cursor position at the beginning in text-box. how can i set position End of text-box value.

DEMO
I am try j-query code for this problem —

var input = $("#txt1"); // textbox Id

var len = input.val().length;

input[0].focus();

input[0].setSelectionRange(len, len);

TRY WITH JQUERY CODE

WITH JQUERY problem is resolved but why cursor set beginning in IE-10(window -7 SP-1)?

And any any other solution for this.

Best Answer

This appears to be an implementation choice on the part of the browser. I can't find anywhere in the HTML spec where it says where the cursor should be positioned when a text input gains focus. If you use the mouse to give an input focus, the cursor is at the clicked position in IE10, Firefox and Chrome, but absent a click event, the browsers seem to do their own thing - Chrome, for example, appears to select the entire contents of the input.