jquery scroll to top of div code example

Example 1: jquery scroll to top of div

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

Example 2: smooth scroll to top jquery

window.scrollTo({top: 0, behavior: 'smooth'});

Example 3: scroll to top jquery

window.scrollTo({top: 0, behavior: 'smooth'});

reference : https://stackoverflow.com/questions/15935318/smooth-scroll-to-top

Example 4: jquery scroll to element

$("#button").click(function() {
    $([document.documentElement, document.body]).animate({
        scrollTop: $("#elementtoScrollToID").offset().top
    }, 2000);
});

Tags:

Misc Example