4
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.

petko_stankoski
  • 10,459
  • 41
  • 127
  • 231

1 Answers1

9

I used the following hack for firefox:

var value = editor.val();
editor.val("");
editor.focus();
editor.val(value);

Here is working fiddle: http://jsfiddle.net/vyshniakov/p37ax/

Artem Vyshniakov
  • 16,355
  • 3
  • 43
  • 47