Created
June 15, 2016 13:43
-
-
Save adisuryadi/dcb4867dc7d00dd8c1f4482010ccfa12 to your computer and use it in GitHub Desktop.
move caret to beginning
This file contains 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 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