16

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!)

Marcel Korpel
  • 21,536
  • 6
  • 60
  • 80
nvcnvn
  • 4,991
  • 8
  • 49
  • 77

3 Answers3

16

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.

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
5

Make sure that overflow property is set:

<div id="divscroll" style="height: 100px; width: 100px; overflow: scroll;">
 //// something something 
</div>
Scherbius.com
  • 3,396
  • 4
  • 24
  • 44
1

Try setting the scroll position to a real figure, instead of just an arbitrary big number:

document.getElementById("divscroll").scrollTop = document.getElementById("divscroll").scrollHeight; 
Chris Baker
  • 49,926
  • 12
  • 96
  • 115
  • `scrollHeight` will still be larger than the largest possible value of `scrollTop` (unless the element has zero height, but that's another problem). – Matt Ball Jun 13 '11 at 16:12