Smooth scroll to div id jQuery

jquery scroll to div codepen
scroll to id jquery
onclick scroll to div javascript
jquery smooth scroll to anchor
jquery jump to id
jquery scroll to element in div
scroll to particular div position when click on link
scroll to div css

I've been trying to get a scroll to div id jquery code to work correctly. Based on another stack overflow question i tried the following


$('#myButton').click(function() {
   $.scrollTo($('#myDiv'), 1000);

But it didn't work. It just snaps to the div. I also tried

$('#myButton').click(function(event) {
   $.scrollTo($('#myDiv'), 1000);

With no progress.

You need to animate the html, body


$("#button").click(function() {
    $('html, body').animate({
        scrollTop: $("#myDiv").offset().top
    }, 2000);

Scroll to a div using jquery, This is a functions that scrolls to #{blah}link function goToByScroll(id) { // Remove "link" from the ID id So you might smooth scroll something. First get the position of the div element upto which u want to scroll by jQuery position() method. jQuery HTML Smooth Scrolling to div is a scroll to particular div with animations when user clicks on a particular button in this case.So, in this tutorial we will show you how to smooth scroll to div using jQuery.You may also like auto scrolling page using jQuery. CHECK OUT THIS TUTORIAL LIVE DEMO →

If you want to override standard href-id navigation on the page without changing the HTML markup for smooth scrolling, use this (example):

// handle links with @href started with '#' only
$(document).on('click', 'a[href^="#"]', function(e) {
    // target element id
    var id = $(this).attr('href');

    // target element
    var $id = $(id);
    if ($id.length === 0) {

    // prevent standard hash navigation (avoid blinking in IE)

    // top position relative to the document
    var pos = $id.offset().top;

    // animated top scrolling
    $('body, html').animate({scrollTop: pos});

Smooth Scroll to ID with jQuery – Tania Rascia, Here's a quick snippet of jQuery code I use often when I need to smoothly scroll to an ID. Just change the to whatever speed (in… Smooth Scroll to Div using jQuery Scroll to Div. The Scroll to Div functionality is very useful for single page website. Auto Scroll to Div. The following code snippet helps to scroll automatically to specific div by class/id Conclusion. Hope, this short and simple script help you to add smooth

here is my 2 cents:


$('.scroll').click(function() {
        scrollTop: eval($('#' + $(this).attr('target')).offset().top - 70)
    }, 1000);


<a class="scroll" target="contact">Contact</a>

and the target:

<h2 id="contact">Contact</h2>

Smooth Scroll to Div using jQuery, Scroll to Div. HTML Code: Specify the element ID with hash (#) prefix in the href attribute value Duration: 4:59 Posted: May 29, 2019 Chrome, IE10+, FireFox, Opera, Safari#scroll to#smooth scroll. Yet another jQuery based smooth scroll script which smoothly scrolls the web page to a specific point/ID/anchor/DIV within the document. Also has the ability to automatically update the url hash when the smooth scroll is completely finished.

Here's what I use:

<!-- jquery smooth scroll to id's -->   
$(function() {
  $('a[href*=#]:not([href=#])').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
      if (target.length) {
          scrollTop: target.offset().top
        }, 500);
        return false;

The beauty with this one is you can use an unlimited number of hash-links and corresponding ids without having to execute a new script for each.

If you’re using WordPress, insert the code in your theme’s footer.php file right before the closing body tag </body>.

If you have no access to the theme files, you can embed the code right inside the post/page editor (you must be editing the post in Text mode) or on a Text widget that will load up on all pages.

If you’re using any other CMS or just HTML, you can insert the code in a section that loads up on all pages right before the closing body tag </body>.

If you need more details on this, check out my quick post here: jQuery smooth scroll to id

Hope that helps, and let me know if you have questions about it.

Add smooth scrolling to page anchors, Smooth Scrolling to div is a scroll to particular div with animations when user of Smooth Scrolling Div Using jQuery </p> </div> <div id="div2"  javascript jQuery Here's a quick snippet of jQuery code I use often when I need to smoothly scroll to an ID. Just change the 500 to whatever speed (in milliseconds) you want the page to scroll at.

one example more:

HTML link:

<a href="#featured" class="scrollTo">Learn More</a>


  $(".scrollTo").on('click', function(e) {
     var target = $(this).attr('href');
     $('html, body').animate({
       scrollTop: ($(target).offset().top)
     }, 2000);

HTML anchor:

  <div id="featured">My content here</div>

Smooth Scrolling To Div Using jQuery, okay so here is what i have so far $('a[href^="#"]').click(function() { $('html,body').​animate({ scrollTop: $(this.hash).offset().top}, 200); return false; // Using jQuery's animate() method to add smooth page scroll // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area $('html, body').animate({

Jquery Smooth Scroll to a name and id, You know that special effect where you click on a link and your browser smoothly scrolls down to the appropriate section of the page? Smooth scrolling when clicking an anchor link. Asked 8 years, 3 months ago. Active 6 days ago. Viewed 757k times. I have a couple of hyperlinks on my page. A FAQ that users will read when they visit my help section. Using Anchor links, I can make the page scroll towards the anchor and guide the users there. Is there a way to make that scrolling

Smoothly scroll to an element without a jQuery plugin · A Beautiful Site, Animated scroll to #anchor / id function with jQuery For some reason the scrolling is not smooth but this is going to work when you do it on a  Is it possible to scroll to a specific location on the page using jQuery? How can I scroll to a specific location on the page using jquery? Scroll to a div

Animated scroll to anchor/id function with jQuery Script, Analyze HTML; Maximize HTML Editor; Minimize HTML Editor; Fold All; Unfold All. 9. 1. <div class="top">. 2. <h1>Top</h1>. 3. </div>. 4. <div class="middle">. 5. In the above jQuery Scroll to Element code it is quite clear that on clicking the Scroll to Target link the user will be scrolled to the div called targetDiv. Now create the jQuery Scroll features for the click event on the anchor tags. The click event is applied to only those anchor tags whose href attribute starts with #.

  • Have you looked at this?…
  • @TheVanillaThrilla I did but it seemed too bloated for a single link use
  • @StevenPHP, I have replaced JavaScript code in your example in accordance with my answer And it works
  • The OP is old but I will share this post for others coming from SE. Here is an article that share a simple function solving the problem:…
  • @vector I have one issue, once it's clicked I have to fight with jquery to scroll up, any solution?
  • @yesitsme ...up or down in my case
  • @GraySpectrum up, only right after clicking, sounds like there's a delay.
  • I have the same question, what if i have few buttons that need to scroll to different locations, tried modifying this code but it does not work. Could you please provide another example?
  • Found some "fix" for it. Scrolling of the proper element is now fixed, but still it goes up and down by clicking on same "scroll-to" target: var target = $(this).data("target"); $(".basics-content").animate({scrollTop: $(target).offset().top}, 1000); }); Explanation: .basics-content is the inner div of the modal which I actually want to scroll to, with target I provide the id number of the element ...
  • This works well, may I suggest a very small tweak var pos = $(id).offset().top; can be var pos = $id.offset().top;
  • Very nice. If you only want this to happen on certain links (say you have some to show or hide information), just add a class name to them and tack your class name (say scroller) to the end of the match declaration ( e.g. a[href^="#"].scroller ).
  • How do you do that without jQuery?
  • This seams to work only if you don't declare doctype.