Cross-Browser method for setting ScrollTop of an element?

nvcnvn picture nvcnvn · Jun 13, 2011 · Viewed 27.7k times · Source

For example I have I a div tag with the scroll bar on the right of the div tag.
I want to show the div with the last line, so I have this:

document.getElementById("divscroll").scrollTop = 250000;

I can make it scroll to the end in Firefox but never succcess with IE event with the bigger number!
Is there any simple Cross-borwser script (not JQuery or any big framework!)

Answer

Matt Ball picture Matt Ball · Jun 13, 2011

scrollTop works in all major browsers.

To scroll to the bottom of the element:

var div = document.getElementById('divscroll');
div.scrollTop = div.scrollHeight - div.clientHeight;

clientHeight also works across browsers, and scrollHeight mostly works.