1

Possible Duplicate:
Use jQuery to scroll to the bottom of a div with lots of text

I have a div where load a number of comments from a database. The div has a height expressed in em not px. It also has enabled the overflow.

When I write a comment and send it recharges I want the scroll to move to the end of the div. Using $("# boxcoment"). ScrollTop (400) within the succes and working properly I automatically moves the scroll.

But I work with em and want to know if .scrollTop() works with em or if there is another way to scroll down to the end of the div.

I tried also with:

height = $("#boxcoment").height();
$("#boxcoment").scrollTop(height);

But the scroll just stops halfway.

Thanks

Community
  • 1
  • 1

2 Answers2

2

You can use scrollHeight property of the DOM Element object.

Height of the scroll view of an element; it includes the element padding but not its margin.

var $box = $('#boxcoment'); 
var height = $box.get(0).scrollHeight;
$box.scrollTop(height);
Ram
  • 143,282
  • 16
  • 168
  • 197
0

Try this:

  var docHeight = $(document).height();

  $("#boxcoment").scrollTop(docHeight);
  //or
  $('html, body').animate({ scrollTop:docHeight+'px'},444);
Barlas Apaydin
  • 7,233
  • 11
  • 55
  • 86