Why scroll to top not working when I use jQuery?



I have a popup that is dynamically loading content and using overflow: auto to maintain the popup size and in turn make it scrollable. I have a link at the bottom currently using anchors to scroll to the top of the div. Unfortunately it is also forcing the page to scroll down to that point as well as scroll to the top of that div.

I am trying to prevent the page from scrolling and only scroll to the top of the div. I have tried numerous scenarios of scroll to top:

$('#id').scrollTop(0);

as well as

$('#id').animate({
   scrollTop: 0
}, 'slow');

Unfortunately this is doing nothing. I am not getting any errors. I have attempted to try it in a console and not attached to any click event and it does nothing and just prints the id to the console that I am targeting.

Here is the link to the actual production version of this page. If you click the link for privacy policy, terms or learn more and then hit any of the back to top links you will see what the issue is.

Here is the site

Answer

i used

$( 'html, body' ).animate( { scrollTop: 0 }, 0 );


Source: stackoverflow