Scroll to the bottom of a textarea using jQuery

Posted by ben 8. May 2010 02:35

This took me way too long to figure out, so I hope it helps some folks.

Seems that $('#yourtextarea').scrollHeight doesn't work. Instead you need to do $('#yourtextarea')[0].scrollHeight.

Example (scolls to bottom of textarea with id "console"):

    <script type="text/javascript">
        $(document).ready(function() {
            var psconsole = $('#console');
            psconsole.scrollTop(
                psconsole[0].scrollHeight - psconsole.height()
            );
        });
    </script>

Tags:
Categories Development | jQuery

blog comments powered by Disqus