In this tutorial we will learn How to Scroll Page to the Bottom using jQuery. We can use jQuery scrollTop() method and height() method which will scroll the page vertically to the calculated height of page.
Table of Contents
jQuery scrollTop() method
jQuery scrollTop() method sets or returns the vertical scrollbar position of the web page or selected HTML element.
In this example scrollTop() method is used to scroll page to the bottom.
HTML Code
HTML Code is given below, in this code we have a button tag which is used to trigger the main function to scroll the page to the bottom.
<!DOCTYPE html>
<html>
<head>
<title>jQuery Scroll Page to the Bottom</title>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</head>
<body style="height: 2000px;">
<button id="btn">Scroll to Bottom</button>
<script src="script.js"></script>
</body>
</html>
JQuery Code
JQuery Code is given below, jQuery click() method will execute a function on click of a button.
Inside this function scrollTop() method will move the scrollbar to the bottom of page.
variable height contains the total height of the document which is calculated using the jQuery height() method.
$(document) represents the whole document or the webpage.
<script>
$(document).ready(function() {
$('#btn').click(function(){
var height = $(document).height();
$(document).scrollTop(height);
});
});
</script>
Demo
Video Tutorial
Watch video tutorial on How To Scroll Page to the Bottom with jQuery.