How to scroll the browser viewing port to the top of the page after sending ajax?

I have a form to upload - after the user submits the form, I would like to scroll the window back to the top of the page (where I will show the help text). How to scroll the window to the top of the page?

+7
jquery
source share
3 answers

To do this, you can use the scroll method for the window object:

window.scroll(0,0) 

Arguments are a horizontal and vertical measure of scrolling in a window, so 0.0 returns it to the beginning.

+8
source share

Since you are using jQuery, you can try the ScrollTo plugin , which you can customize.

+1
source share

Can't you use the .focus () event for any tag at the top of the page?

 $("input#myFirstName").focus(); 
+1
source share

All Articles