Last active
November 26, 2015 06:14
-
-
Save jobyjoseph/72060824a5169885a137 to your computer and use it in GitHub Desktop.
SetCaretAtEnd function accepts a javascript dom object and sets cursor to end.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function SetCaretAtEnd(elem) { | |
var elemLen = elem.value.length; | |
// For IE Only | |
if (document.selection) { | |
// Set focus | |
elem.focus(); | |
// Use IE Ranges | |
var oSel = document.selection.createRange(); | |
// Reset position to 0 & then set at end | |
oSel.moveStart('character', -elemLen); | |
oSel.moveStart('character', elemLen); | |
oSel.moveEnd('character', 0); | |
oSel.select(); | |
} | |
else if (elem.selectionStart || elem.selectionStart == '0') { | |
// Firefox/Chrome | |
elem.selectionStart = elemLen; | |
elem.selectionEnd = elemLen; | |
elem.focus(); | |
} // if | |
}; | |
SetCaretAtEnd($('.m-status-item .editPostInput')[0]); // This is how a jQuery object is passes. note [0]. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment