Avoiding Resetting the Scroll Position in a Textarea When Inserting Content

Now, that’s quite a headline. And this post will explain just the simple concept posted in the headline. How to avoid (at least) firefox from scrolling to the top when you insert content into a textarea.

It’s simple. Very simple. And it was shown to be so very simple for someone who didn’t remember scrollTop by this thread.

In jQuery (which we use with the caret plugin):

currentScrollPosition = $("#textareaId").scrollTop();
/* do stuff */
$("#textareaId").scrollTop(currentScrollPosition);

Yep. So simple that it actually hurts a bit.

2 thoughts on “Avoiding Resetting the Scroll Position in a Textarea When Inserting Content”

  1. Thanks for the post. Wow, you gave me the answer that tortured me for severaal days. I ndint know how to avoid firefox from scrolling to the top when I insert content into a textarea. Now, I see it is really very simple) Thanks again!

Leave a Reply

Your email address will not be published. Required fields are marked *