How to jump to top of browser page using jQuery?
When the website contains lots of data on a single page and while seeing down the website, if the user wants to see the main content i.e, top of the browser page without scrolling, this can be achieved by using jQuery.
Example: Jump to the top of the browser page
<html> <head> <script src= </script> <script> $(function () { $('#Top').click(function () { $('html, body').animate( { scrollTop: '0px' }, 1500); return false; }); }); </script> </head> <body> <center> <h1>GeeksforGeeks</h1> <h2>Welcome to GeeksforGeeks</h2> <h4>Glad to see you!!</h4> <h5>A Computer Science portal for the geeks.</h5> <p>It is the complete portal for learning in Computer Science field.</p> <p>GeeksforGeeks portal contain every basic to hard knowledge regarding Computer Science field.</p> <p>You can also share interview experience here to help other geeks.</p> <p>It also focuses on GATE, provides notes, previous year question papers, last minute notes, etc.</p> <p>GeeksforGeeks provides opportunity for the geeks to contribute and help other geeks.</p> <a id="scrlTop" href="#">Scroll to Top</a> </center> </body> </html> |
Output :
Before clicking on “Scroll to Top”


After clicking on “Scroll to Top”

In the above example, when we click “Scroll to Top” link, it automatically jump to the top of the browser page.
Recommended Posts:
- How to get the size of screen, current web page and browser window using jQuery?
- How to refresh a page using jQuery?
- Scroll to the top of the page using JavaScript/jQuery
- How to scroll automatically to the Bottom of the Page using jQuery?
- How to disable dragging an image from an HTML page using JavaScript/jQuery ?
- JQuery | Set focus on a form input text field on page load
- How to display search result of another page on same page using ajax in JSP?
- Difference between Web Browser and Web Server
- How to open a PDF files in web browser using PHP?
- How to give a div tag 100% height of the browser window using CSS
- JavaScript | Detecting a mobile browser
- How to share code between Node.js and the browser?
- How to detect browser or tab closing in JavaScript ?
- How to close current tab in a browser window using JavaScript?
- How to disable browser Autocomplete on web form field/input tag?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



