editor.focus();
Sets the focus fine in Chrome. But in Firefox, the focus is set on the beginning on the line. I want it to be set on the end of the line. I tried this:
moveCaretToEnd(ed);
function moveCaretToEnd(el) {
if (typeof el.selectionStart == "number") {
el.selectionStart = el.selectionEnd = el.value.length;
} else if (typeof el.createTextRange != "undefined") {
el.focus();
var range = el.createTextRange();
range.collapse(false);
range.select();
}
}
And stupid FF doesn't work again. The focus is gone.
editor.focus();
Sets the focus fine in Chrome. But in Firefox, the focus is set on the beginning on the line. I want it to be set on the end of the line. I tried this:
moveCaretToEnd(ed);
function moveCaretToEnd(el) {
if (typeof el.selectionStart == "number") {
el.selectionStart = el.selectionEnd = el.value.length;
} else if (typeof el.createTextRange != "undefined") {
el.focus();
var range = el.createTextRange();
range.collapse(false);
range.select();
}
}
And stupid FF doesn't work again. The focus is gone.
Share Improve this question asked Oct 16, 2012 at 9:10 petko_stankoskipetko_stankoski 10.7k42 gold badges134 silver badges234 bronze badges 1- Could you provide jsfiddle demo for this? – Om3ga Commented Oct 16, 2012 at 9:14
1 Answer
Reset to default 9I used the following hack for firefox:
var value = editor.val();
editor.val("");
editor.focus();
editor.val(value);
Here is working fiddle: http://jsfiddle/vyshniakov/p37ax/