Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save adisuryadi/dcb4867dc7d00dd8c1f4482010ccfa12 to your computer and use it in GitHub Desktop.
Save adisuryadi/dcb4867dc7d00dd8c1f4482010ccfa12 to your computer and use it in GitHub Desktop.
move caret to beginning
function moveCaretToStart(el) {
if (typeof el.selectionStart == "number") {
el.selectionStart = el.selectionEnd = 0;
} else if (typeof el.createTextRange != "undefined") {
el.focus();
var range = el.createTextRange();
range.collapse(true);
range.select();
}
}
moveCaretToStart(document.forms["post"].elements["message"]);
// credit: http://stackoverflow.com/questions/3356770/need-cursor-at-beginning-of-text-in-textarea/3357143#3357143
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment