Files
DiceCloud/rpg-docs/lib/functions/placeCaretAtEnd.js

18 lines
661 B
JavaScript

placeCaretAtEnd = function(el) {
el = el.get(0); //jquery element -> DOM element
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();
}
}