Kuba Żukowski
Kuba Żukowski

Reputation: 663

Auto scrolldown after update DIV content

I have DIV with scroll-y and I update content on this DIV via $.get. I don't know how I can make auto scrolldown when new content (on DIV) is longer than old content.

CSS

#chat-conversations{
    background-color: red;
    width: 150px;
    height: 300px;
    overflow-x: hidden;
    overflow-y: scroll;
}

Here is the Code

Upvotes: 0

Views: 185

Answers (1)

Ravikumar Sharma
Ravikumar Sharma

Reputation: 3740

Try setting your div's scrolltop to your div's scrollHeight.

var yourDiv = document.getElementById("chat-conversations");
yourDiv.scrollTop = yourDiv.scrollHeight;

Put this inside $.get's Callback function after appending content to div, this will auto scroll div to the new content.

Update: Sorry bruv. i left a typo.corrected now

Upvotes: 2

Related Questions