0 points

Move Cursor to End of Input | JavaScript


dashboard

Sat May 16 2020 06:23:00 GMT+0000 (UTC)

Posted by @RedQueen #javascript

function moveCursorToEnd(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();
    }
}
content_copy Copy

https://css-tricks.com/snippets/javascript/move-cursor-to-end-of-input/