June 2, 2010
how to set focus on top of the page
Question by vakas
How do I set focus to the top of a page?
Answer by Starx
It would be helpful if you write a little so that we can understand your problem.
A very easy way is linking to class or id on a page.
For example this page “page.html”
<body>
<div id="top"> ..................Content................</div>
<div id="otherdiv">........................</div>
</body>
then if you need to focus on top, send a link like “page.html#top” the page will automatically focus on top
or if you want to stick to javascript then do this
document.location.href = '#top'; //to send it to the top
But I would say use simple html anchor to go to top like
<a href="#top">Back to Top</a>