Desiring to scroll down along with my selected document, I experimented with the following code.
window.scrollTo(x, y);
const body = document.getElementsByClassName("body")[0];
body.scrollTo(x, y);
However, there are instances where it returns "undefined".
Edit 1: Fortunately, I found a solution and have provided the snippet below that aided me.
- To scroll the entire page:
window.scrollTo(x, y)
- To scroll a selected div (it must have a lengthy area to enable scrolling down):
document.getElementsByClassName("body")[0].scrollTo(x, y)