Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
12
rated 0 times [  18] [ 6]  / answers: 1 / hits: 41052  / 12 Years ago, tue, august 21, 2012, 12:00:00

I am trying to use jQuery to scroll the page automatically back to the top when the page is loaded.
Here is my code:



<script type=text/javascript>
$(document).ready(function () {

$(window).scrollTop(0);
return false;

});
</script>


However, the code does not work.
I have also tried to replace $(window) to $('html, body'),
sadly it still does not work.



So could anyone advice on this?
Thanks a lot!


More From » jquery

 Answers
28

Try this



<script type=text/javascript>
$(document).ready(function () {
window.scrollTo(0,0);
});
</script>


The parameters 0,0 are the x and y coördinates.



I hope it helps.


[#83521] Sunday, August 19, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nadineannabellet

Total Points: 464
Total Questions: 94
Total Answers: 97

Location: Maldives
Member since Tue, Dec 21, 2021
2 Years ago
;