Q:

Find when user has scrolled to the end of a given table

How do I find out if a user has scrolled to the end of a table using jQuery?  I can find when the user scrolls to the end of a page using this:
if( document.body.scrollHeight - $( window ).scrollTop()  <= $( window ).height() ) {
  // do something
}

but how do I do this with a table e.g. $(#table-name) ?
Many thanks :).

A:

Try this.
$(document).scroll(function() {
    var $table = $("#table-name");

    if ($table.position().top + $table.height() - $(window).height() <= $(window).scrollTop()) {
        console.log('Reached end of table');
    }
});

Demo

