Hello Friends, today I will tell you through this tutorial how you can scroll to the top of page by jquery. So let’s go.
Follow 2 steps & complete solution.
Step 1:- Create HTML file.
Step 2:- Add Jquery code in html file.
Step 1:- Create HTML file.
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<meta charset="utf-8">
<title>Scroll to the top of the page with jQuery</title>
</head>
<body>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<p>jquery scroll top of the page</p>
<a href='#top'>Go To Top</a>
</body>
</html>
Step 2:- Add Jquery code in html file.
<script>
$("a[href='#top']").click(function() {
$("html, body").animate({ scrollTop: 0 }, "slow");
return false; });
</script>