Ryan Castle
Ryan Castle

Reputation: 247

How would I make a div automatically scroll to the bottom?

I want my div to automatically stay at the bottom when a paragraph is added, how would I do this? This is my code:

http://pastebin.com/wespDUXp

Upvotes: 0

Views: 581

Answers (1)

gfrobenius
gfrobenius

Reputation: 4067

Here you go: http://jsfiddle.net/tMnvJ/

Just put that JavaScript code in a function and call it by whatever process adds your content. Something like this...

function addParagraph()
{
    //do you add paragraph stuff...
    //then call this line to scroll to the bottom of your div
    document.getElementById('myDiv').scrollTop = document.getElementById('myDiv').scrollHeight;
}

Hope that helps.

Upvotes: 2

Related Questions