How to run jQuery code when user scrolls to end of specific element?

javascript, jquery

Solution

This should probably work.

$(window).scroll(function () {
    if ($(window).scrollTop() >= $(elem).position().top + $(elem).height() /* add padding if needed. */) {

            // Run code here...

    }
});

Problem

Here is my sample code: ``` $(window).scroll(function () { if ($(window).scrollTop() >= $(document).height() - $(window).height()) { // Run code here... } }); ``` I use the above code to execute stuff when user scroll to bottom of page. Instead, how can I make the code executed when user scroll to bottom of specific element (e.g. #content) and not the whole document. Thank you.

Original source