How to scroll automatically to a particular element using JQuery? Last Updated : 03 Aug, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report The task is to scroll to a particular element automatically. Below are the approaches: Approach 1: Get the height of the element by .position().top property. Use .scrollTop() method to set the vertical position of the scrollbar equal to the calculated height of the particular element. Example 1: This example uses the approach discussed above. html <!DOCTYPE HTML> <html> <head> <title> How to scroll automatically to a particular element. </title> <style> #GFG_DOWN { margin-top: 370px; } </style> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksForGeeks </h1> <p id="GFG_UP" style="font-size: 15px; font-weight: bold;"> </p> <button onclick="gfg_Run()"> Click Here </button> <p id="GFG_DOWN" style="color:green; font-size: 30px; font-weight: bold;"> This is element. </p> <script> var el_up = document.getElementById("GFG_UP"); var el_down = document.getElementById("GFG_DOWN"); el_up.innerHTML = "Click on the button to scroll to the particular element."; function gfg_Run() { $(window).scrollTop($('#GFG_DOWN').position().top); } </script> </body> </html> Output: Before clicking on the button: After clicking on the button: Approach 2: Get the height of the element by .offset().top property. Use .animate() method to animate to the element. Example 2: This example uses the approach discussed above. html <!DOCTYPE HTML> <html> <head> <title> How to scroll automatically to a particular element. </title> <style> #GFG_DOWN { margin-top: 400px; } </style> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksForGeeks </h1> <p id="GFG_UP" style="font-size: 15px; font-weight: bold;"> </p> <button onclick="gfg_Run()"> Click Here </button> <p id="GFG_DOWN" style="color:green; font-size: 30px; font-weight: bold;"> This is element. </p> <script> var el_up = document.getElementById("GFG_UP"); var el_down = document.getElementById("GFG_DOWN"); el_up.innerHTML = "Click on the button to scroll to the particular element."; function gfg_Run() { $('html, body').animate({ scrollTop: $("#GFG_DOWN").offset().top }, 500); } </script> </body> </html> Output: Before clicking on the button: After clicking on the button: jQuery is an open source JavaScript library that simplifies the interactions between an HTML/CSS document, It is widely famous with it's philosophy of “Write less, do more". You can learn jQuery from the ground up by following this jQuery Tutorial and jQuery Examples. Comment More infoAdvertise with us Next Article How to scroll automatically to a particular element using JQuery? P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies JQuery jQuery-Misc Similar Reads How to scroll automatically to the Bottom of the Page using jQuery? We are given an webpage and the task is to automatically scroll to the bottom of the page using jQuery.Below are the approaches to achieve this:Table of ContentUsing the scrollTop with height() methodUsing scrollTop with animate() methodUsing the scrollTop with height() methodIn this approach, we wi 3 min read How to Scroll to an Element Inside a Div using JavaScript? To scroll to an element within a div using JavaScript, set the parent div's scrollTop`to the target element's offsetTop. This method allows smooth navigation within a scrollable container. Below are the methods to scroll to an element inside a Div using JavaScript:Table of Content Using scrollIntoVi 3 min read How to change style of elements on scroll using jQuery ? We have given an HTML document containing some CSS properties, and the task is to change the CSS property to a particular element after scrolling the page using jQuery. To change the style of element on scroll, we get the number of pixels by which the content of an element has been scrolled horizont 2 min read How to scroll to specific element using jQuery ? Many times, in our website we want to scroll automatically to a section of the webpage when we click on a button or a heading in a navbar or a list. So, to achieve this automatic scrolling to the required element, we need to take the help of jQuery. Using jQuery, we can achieve this in a very simple 3 min read How to scroll the page up or down using anchor element in jQuery ? The problem is to include a slide effect whenever we click a local anchor and we want to scroll up or down the page accordingly. Earlier we can do it natively by using CSS property. Syntax: a { scroll-behavior: smooth; } Now with the help of jQuery, we can do it by using the following two methods: j 2 min read Like