focus,end,js,focus,place,caret,at,end

Kubilay 7/27/2016 0

this code will let you move caret at the end of text, focus end of text

JavaScript
 function placeCaretAtEnd(el) {
    el.focus();
    if (typeof window.getSelection != "undefined"
            && typeof document.createRange != "undefined") {
        var range = document.createRange();
        range.selectNodeContents(el);
        range.collapse( false);
        var sel = window.getSelection();
        sel.removeAllRanges();
        sel.addRange(range);
    } else if (typeof document.body.createTextRange != "undefined") {
        var textRange = document.body.createTextRange();
        textRange.moveToElementText(el);
        textRange.collapse( false);
        textRange.select();
    }
}


var focusNode = window.getSelection().focusNode;
placeCaretAtEnd(focusNode);
 

Report Bug

Please Login to Report Bug

Reported Bugs

Comments

Please Login to Comment

Comments