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.
1//scroll to the bottom of "#myDiv"
2var myDiv = document.getElementById("myDiv");
3 myDiv.scrollTop = myDiv.scrollHeight;
1// if using jQuery
2function scrollSmoothToBottom (id) {
3 var div = document.getElementById(id);
4 $('#' + id).animate({
5 scrollTop: div.scrollHeight - div.clientHeight
6 }, 500);
7}
8
9//pure JS
10function scrollToBottom (id) {
11 var div = document.getElementById(id);
12 div.scrollTop = div.scrollHeight - div.clientHeight;
13}
1//For a smooth scroll using jQuery animate
2$('#DebugContainer').stop().animate({
3 scrollTop: $('#DebugContainer')[0].scrollHeight
4}, 800);
5