0

I have a div and it has a scroll bar here is the code I've used:

<div style="width: 200px; height: 250px; overflow: scroll; overflow-x: hidden; -ms-overflow-x: hidden;" id="container"></div>

There will be more text added to the div but when the div does expand how can I have the vertical scroll bar remain at the bottom of the bar so the user can see the appended text?

John Doe
  • 3,559
  • 15
  • 62
  • 111
  • Scroll to the bottom after adding? As long as you can guarantee you're not adding too much that you miss something. – Dave Newton Oct 16 '11 at 17:30

2 Answers2

3

You should set the scrollTop to scrollHeight, e.g.: http://jsfiddle.net/fAK2L/1/.

var div = $('div');
div.scrollTop( div.get(0).scrollHeight );
pimvdb
  • 151,816
  • 78
  • 307
  • 352
1

Use element.scrollIntoView for the last added element

hungryMind
  • 6,931
  • 4
  • 29
  • 45