Find div closest to the bottom of the page
<p>I am working on a project and I have an array of elements that are displayed one under each other.</p>

<p>When I press an arrow, I want to find the div closest to the bottom and scroll up to the top of that div.</p>

<p>This is what I have when I click the arrow:</p>

<pre><code>$(".my-elements").each(function(i){
    var divTopPosition = $(this).offset().top;
    var scrollTop = $(window).scrollTop();

    var difference = -Math.abs(scrollTop - divTopPosition);

    if(/* this is the div closest to the bottom */)
    {
        $("body").animate({scrollTop: difference}, 2000);
        return false;
    }
});
</code></pre>