Knowing the jQuery Caret plugin, I\'m still seeing no way to do the following on a single line text box in HTML (i.e. the input:type=text
control) with JavaScript:<
If you want to put the caret at the end and scroll to the bottom of a textarea, this works perfectly :
function moveCaretToEnd(el) {
if (typeof el.selectionStart == "number") {
el.selectionStart = el.selectionEnd = el.value.length;
} else if (typeof el.createTextRange != "undefined") {
el.focus();
var range = el.createTextRange();
range.collapse(false);
range.select();
}
setTimeout(function(){
var pos = $(el).offset().top + $(el).height();
$('html, body').animate({
scrollTop: pos
}, 1000);
},100);
}
moveCaretToEnd(document.getElementById("replyBox"));
It will place the caret at the end, and then smoothly scroll the window to the bottom.