To scroll to top of page with JavaScript, we set the scrollTop
property of the body element to 0.
For instance, we write
document.body.scrollTop = document.documentElement.scrollTop = 0;
to set document.body.scrollTop
and document.documentElement.scrollTop
to 0 to scroll to the top of the page.