When I try to do .focus() I expect to set focus on input element and to see cursor after last character of the value. And I see it in IE.
In safari/chrome input gets focus and all text is selected.
In firefox/opera input gets focus, but cursor is in the beginning.
What could I do to prevent that and get correct behavior for all browsers?
An example is here: http://jsbin.com/ozojol/edit#javascript,html
PS. focus().val('').val(value) method doesn’t work in IE… What other workarounds exist?
You can use the input’s
selectionStartandselectionEndproperties in most browsers and some nastyTextRangestuff in IE < 9. Here’s some code adapted from an answer to a similar question.Demo: http://jsbin.com/azapuy
Code: