Javascript - Position Caret


How can we position the caret?

var el = cmp.el.dom;
if (el.createTextRange) {
    var range = el.createTextRange();
    var pos = el.value.length;
    range.moveStart("character", pos);;
} else if (el.setSelectionRange) {

The above code works for IE11 (with compatibility view setting on). I used the above code position the caret at the end of an input field. See

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License