Search code examples
javascriptjqueryscroll

jquery - scroll page to bottom


I simply want to scroll a page to the bottom
seems - it is a deep secret

$(window).on('load', function(){
    let y = $('body').height();
    console.log(y);  // 2285
    $('document').scrollTop(y);
});

also tried:

$('document').scrollTop(y + 'px');  
$('body').scrollTop(y);
$('body').scrollTop(y + 'px');

also tried some code from here - without success

please help


Solution

  • Here is the alternative way. It works for me.

    <script>
      jQuery(document).ready(function () {
        jQuery("button").click(function () {
          jQuery("html, body").animate(
            {
              scrollTop: jQuery("html, body").get(0).scrollHeight,
            },
            1000
          );
        });
      });
    </script>