Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make the web browser scroll to the top?

What is the JavaScript to scroll to the top when a button/link/etc. is clicked?

like image 928
David Basarab Avatar asked Feb 03 '26 22:02

David Basarab


2 Answers

<a href="javascript:scroll(0, 0)">Top</a>
like image 152
John Boker Avatar answered Feb 06 '26 10:02

John Boker


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.

like image 24
Rob Rolnick Avatar answered Feb 06 '26 10:02

Rob Rolnick



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!