Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to jump to top of browser page

People also ask

How do I get to the top of the page without scrolling?

Hello, Try using Command key + arrow up (or down). The reason those work is because adding the Fn key turns those keys into Home, End, Page Up, and Page Down. On extended keyboards, you can get to top of page by pressing just the Home key, and the bottom of a page by pressing End.

How do I jump to the top of the page in HTML?

window. scrollTo(0, 0); …is a sure bet to scroll the window (or any other element) back to the top.

How do I scroll to the top of the button click?

window. scroll(0, 0) will work just fine in all browsers.

How do you scroll automatically to the top of the page using JavaScript?

Method 1: Using window.scrollTo() The scrollTo() method of the window Interface can be used to scroll to a specified location on the page. It accepts 2 parameters the x and y coordinate of the page to scroll to. Passing both the parameters as 0 will scroll the page to the topmost and leftmost point.


You can set the scrollTop, like this:

$('html,body').scrollTop(0);

Or if you want a little animation instead of a snap to the top:

$('html, body').animate({ scrollTop: 0 }, 'fast');

Without animation, you can use plain JS:

scroll(0,0)

With animation, check Nick's answer.


If you're using jQuery UI dialog, you could just style the modal to appear with the position fixed in the window so it doesn't pop-up out of view, negating the need to scroll. Otherwise,

var scrollTop = function() {
    window.scrollTo(0, 0);
};

should do the trick.


You could do it without javascript and simply use anchor tags? Then it would be accessible to those js free.

although as you are using modals, I assume you don't care about being js free. ;)