Reputation: 171321
Consider the following example: (demo here)
HTML:
<input type="text" />
<div>Click here to set focus</div>
JS:
$(function() {
$("input").val("Hello");
$("div").click(function() {
$("input").focus();
});
});
When the div
is clicked, the cursor positioned at the beginning of the text: |Hello
.
How could I set the cursor at the end of the text: Hello|
?
Upvotes: 3
Views: 1053
Reputation: 58521
Use this plugin: http://plugins.jquery.com/project/PutCursorAtEnd
Upvotes: 1