views:

128

answers:

3

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

+4  A: 
<a href="javascript:scroll(0, 0)">Top</a>
John Boker
+4  A: 

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.

Rob Rolnick
A: 

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>
scunliffe