jQuery Check if Div Scrolled to End

By Sam Deering

Simple jQuery code snippet to check if you have scrolled to the end of a div and raise an event. Useful when you have an inline element (overflow:scroll) that you want to know if someones scrolled down to the bottom. Could be used to check if someone has read terms and conditions on a registration form.


function chk_scroll(e)
    var elem = $(e.currentTarget);
    if (elem[0].scrollHeight - elem.scrollTop() == elem.outerHeight())


Other ways:

//scrollTop refers to the top of the scroll position, which will be scrollHeight - offsetHeight
if( obj.scrollTop == (obj.scrollHeight - obj.offsetHeight)) { }

No Reader comments



Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in JavaScript, once a week, for free.