Skip to content

Instantly share code, notes, and snippets.

@jawdatls
Created May 11, 2015 08:35
Show Gist options
  • Select an option

  • Save jawdatls/bea1bb8909ce6f422eac to your computer and use it in GitHub Desktop.

Select an option

Save jawdatls/bea1bb8909ce6f422eac to your computer and use it in GitHub Desktop.
javascript set Cursor at position
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