Created
May 11, 2015 08:35
-
-
Save jawdatls/bea1bb8909ce6f422eac to your computer and use it in GitHub Desktop.
javascript set Cursor at position
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 setSelectionRange(input, selectionStart, selectionEnd) { | |
| if (input.setSelectionRange) { | |
| input.focus(); | |
| input.setSelectionRange(selectionStart, selectionEnd); | |
| } | |
| else if (input.createTextRange) { | |
| var range = input.createTextRange(); | |
| range.collapse(true); | |
| range.moveEnd('character', selectionEnd); | |
| range.moveStart('character', selectionStart); | |
| range.select(); | |
| } | |
| } | |
| function setCaretToPos (input, pos) { | |
| setSelectionRange(input, pos, pos); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment