Scroll automatically a part of the page in javascript Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Scroll automatically a part of the page in javascript without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have a project that has a chat app that looks like this:

chat app image

as you can see the scroll bar is not in the window, it is at the chat section, what I want to do is to scroll automatically down of the chat section. I try doing this:

window.scrollTo(0, document.body.scrollHeight);

but that doesn´t work, is there another way to only scroll down only the chat section?

Answer

As I can see on the screenshot, you need to scroll the chat section, not the whole window.

const chatContainer = document.querySelector("#chat-container");

chatContainer.scrollTo(0, chatContainer.scrollHeight)
We are here to answer your question about Scroll automatically a part of the page in javascript - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji