Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

116
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda