Q: Dynamically scrolling a DIV layer down when data is loaded I coded a chat script and I plucking my hair for couple of months to understand how a DIV layer can be scrolled down on loading some data to it using a Databinder with Repreater in ASP.NET with AJAX extensions.
I read a blog today where the author just gave me the logic but not code and I am not an expert in writing highend JavaScripts. Can anybody help me in constructing it.


*

*Get scroll bar position.

*If scroll bar position is not bottom then move to bottom.

*If scroll bar is scrolled up do no action until new item is loaded to Databinder.


Can anybody provide me with the syntax for the above three please.

Or kindly let me know if there is any other way to get rid of my issue.

A: You can use scrollTop property in native JS and $(selector).scrollTop() method in jQuery. In both cases you can assign a value to it to change the scroll position of that element.
Example:
document.getElementById("myDiv").scrollTop = 100;
$("#myDiv").scrollTop(100);

EDIT
var div = document.getElementById('myDiv');
var scrollHeight = div.scrollHeight;
var scrollTop = div.scrollTop;
var height = parseInt(div.style.height);
if(scrollHeight - (scrollTop + height) == 0) {
    // do something when you're at the bottom
} else {
    // do something when you're NOT at the bottom
}

