Last active
October 18, 2017 01:04
-
-
Save kilgarenone/6b030fbfbe8730ab1664 to your computer and use it in GitHub Desktop.
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 placeCaretAtEnd(el) { | |
el.focus(); | |
if (typeof window.getSelection != "undefined" | |
&& typeof document.createRange != "undefined") { | |
var range = document.createRange(); | |
range.selectNodeContents(el); | |
range.collapse(false); | |
var sel = window.getSelection(); | |
sel.removeAllRanges(); | |
sel.addRange(range); | |
} else if (typeof document.body.createTextRange != "undefined") { | |
var textRange = document.body.createTextRange(); | |
textRange.moveToElementText(el); | |
textRange.collapse(false); | |
textRange.select(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment