How to scroll the browser to the desired item by javascript?

advertisements

The question is simple.

How to scroll browser to desired element or desired position by javascript?

Thanks a lot for the help!


To an element :

document.getElementById('id').scrollIntoView();

Has cross browser support and probably the easiest way to do it ....

or to a specific position :

window.scroll(x,y);

Docs for window.scroll() here