You can use this code:
function scrollToLine($textarea, lineNumber) {
var lineHeight = parseInt($textarea.css('line-height'));
$textarea.scrollTop(lineNumber * lineHeight);
}
Some caveats about this code:
- Your textarea needs to have a line-height in Pixels.
- The code will scroll to the line number in the text area, not the line number of the original text. These will differ if any lines wrap at the edge of the textarea.
Also see our solution for scrolling a textarea to a given position with jQuery, which might work better for you. Also some other people have done crazy things Show archive.org snapshot .
Posted by Henning Koch to makandra dev (2012-05-02 22:36)