Getting and changing a window scroll in JavaScript

The following properties contain how much the window is scrolled:

let t = document.documentElement.scrollTop; // from top let l = document.documentElement.scrollLeft; // from left

These properties can be changed to scroll the window to an arbitrary position:

document.documentElement.scrollTop = 200;

By clicking on the button, scroll the window to the position 300px from the top.

By clicking on the button, scroll the window to the position 100px from the bottom.

On button click, scroll the window to the very top.

On button click, scroll the window to the very bottom.

enru