Scroll to div, top using jQuery

Scroll to using jQuery:

Prerequisites:

  • jquery.js

Code:

1Scroll to element:

$("body").on("click", "#triggerDivId", function(){
  $('html,body').animate({
    scrollTop: $('#triggerTopId').offset().top
  })
})

2Scroll to top:

$("body").on("click", "#triggerTopId", function(){
  $('html,body').animate({
    scrollTop: 0
  })
})