Tutorial :Javascript scroll


How to scroll to top of the page in php with javascript

scroll(0,0); -> this is not working? On click of submit, i call a function to validate the form and incase of error i will be setting the errormessage thru innerhtml and need to scroll to top of the page without submitting.

Everything works...but its not scrolling to top of the page


Use window property scrollTop (MSDN, MDC) to set number of pixels to scroll offset.

window.scrollTop = '0';  


If you have a particular element that you want to scroll over, lets say, the element of whose innerHTML you are modifying then you can use the following


Works in all browsers


How about trying window.scrollTo(0,0). It is basically the same thing as scroll(0,0).

If it does not work, show us more code.


Scrolling to the absolute top of the page can be achieved by either



window.location = "#";  

Note that the second method will append "#" to the current URL.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »