0

I used

var items = document.getElementById('messageBody');
items.scrollTo(0, document.getElementById('messageBody').scrollHeight);

where, 'messageBody' is the id of the div with height 400px and vertical scroll in it. This seems to be working fine in Chrome browser but its not working in Firefox. Can someone help me with a fix for this issue in Firefox browser?

Ramya
  • 225
  • 1
  • 6
  • 15

2 Answers2

0

Try this:

var items = document.getElementById('messageBody');
items.scrollTop = items.scrollHeight;
JKD
  • 1,279
  • 1
  • 6
  • 26
0

From Scroll to bottom of div?

Works in Chrome 84 AND Firefox 80 AND 81

var objDiv = document.getElementById("scroll");
objDiv.scrollTop = objDiv.scrollHeight;
#scroll {
  height: 400px;
  overflow: scroll;
}
<div id="scroll">
  <div style="height:200px; background-color:red;">DIV 1</div>
  <div style="height:200px; background-color:blue;">DIV 2</div>
  <div style="height:20px; background-color:yellow;">DIV 3</div>
</div>

ALSO Works in Chrome 84 AND Firefox 80 AND 81

var objDiv = document.getElementById("scroll");
objDiv.scrollTop = objDiv.scrollHeight - objDiv.clientHeight;
#scroll {
  height: 400px;
  overflow: scroll;
}
<div id="scroll">
  <div style="height:200px; background-color:red;">DIV 1</div>
  <div style="height:2000px; background-color:blue;">DIV 2</div>
  <div style="height:20px; background-color:yellow;">DIV 3</div>
</div>
mplungjan
  • 169,008
  • 28
  • 173
  • 236