Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
ScrollTop is not working in Chrome and Firefox

I try to scroll the div of a chat down with JavaScript to the newest message when the user opens the chat, sends or receives a message. For this I tried to use ScrollTop like recommended in many google search results. I made the div element as a global object because I want to use the line with ScrollTop several times in the script. The chatdiv is set to 'overflow-y: scroll;'. I verified with an alert output in the browser console that the window.onload function is working.

<script type="text/javascript">
var element_label = document.getElementById("chatdiv");

window.onload = function WindowLoad(event) {
    element_label.scrollTop = element_label.scrollHeight;
}
</script>

My next try was to get the newest message object and use ScrollIntoView on it. This also did not work.

<script type="text/javascript">
var element_label = document.getElementById("chatdiv");
var last_mess = document.getElementById("chatdiv").lastChild;

window.onload = function WindowLoad(event) {
    last_mess.scrollIntoView();
}
</script>

Am I missing a significant point or is it no longer possible to scroll a div with JavaScript?

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!