Javascript: make the web browser scroll to the top?
-
09-06-2019 - |
Question
What is the Javascript to scroll to the top when a button/link/etc. . . clicked?
Solution
<a href="javascript:scroll(0, 0)">Top</a>
OTHER TIPS
If you had an anchor link at the top of the page, you could do it with anchors too.
<a name="top"></a>
<a href='#top">top</a>
It'll work in browser's with Javascript disabled, but changes the url. :( It also lets you jump to anywhere the name anchor is set.
actually, this works by itself, no need to define it.
<a href="#top">top</a>
This is a "magic" hashname value that does not need to be defined in browsers.
Just like this will "reload" the page.
<a href="/">reload</a>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow