1// To scroll to the bottom of a div
2const theElement = document.getElementById('elementID');
3
4const scrollToBottom = (node) => {
5 node.scrollTop = node.scrollHeight;
6}
7
8scrollToBottom(theElement); // The specified node scrolls to the bottom.
1var notChangedStepsCount = 0;
2var scrollInterval = setInterval(function() {
3 var element = document.querySelector(".element-selector");
4 if (element) {
5 // element found
6 clearInterval(scrollInterval);
7 element.scrollIntoView();
8 } else if((document.documentElement.scrollTop + window.innerHeight) != document.documentElement.scrollHeight) {
9 // no element -> scrolling
10 notChangedStepsCount = 0;
11 document.documentElement.scrollTop = document.documentElement.scrollHeight;
12 } else if (notChangedStepsCount > 20) {
13 // no more space to scroll
14 clearInterval(scrollInterval);
15 } else {
16 // waiting for possible extension (autoload) of the page
17 notChangedStepsCount++;
18 }
19}, 50);