user3740116
user3740116

Reputation: 37

How to set div scrollbar to bottom by default

This is div.

<div id='showmymessage' style="height:490px;overflow:auto;">

Hey nothing is working in my case. Div is set to overflow:auto.

I tried all these ways but scrollbar is not loading at bottom position.

  1. document.getElementById('showmymessage').scrollTop = 99999999999;

  2. var myDiv = document.getElementById('showmymessage'); myDiv.scrollTop = myDiv.scrollHeight;

  3. $('#showmymessage').scrollTop($('#showmymessage')[0].scrollHeight);

Please somebody tell if I made any mistake and try to help.

Upvotes: 1

Views: 5688

Answers (1)

Dave B 84
Dave B 84

Reputation: 618

You want overflow:scroll instead of overflow:auto. Then your javascript should work.

Update

...then again, there's another question very similar where it works with overflow:auto.

Use jQuery to scroll to the bottom of a div with lots of text

It looks like it uses the same as your version 3. Working example:

http://jsbin.com/ucinu

Possibly something else wrong with your code? Check for missing closing tags, javascript errors etc?

Upvotes: 1

Related Questions