Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
9
rated 0 times [  14] [ 5]  / answers: 1 / hits: 74430  / 8 Years ago, thu, december 1, 2016, 12:00:00

I have a scroll-bar in a div element and initially it's position is top. Whenever i add some text to the div element then the scroll-bar does not move. Is there any way, the scroll-bar of the div element's position will be always bottom and whenever I add some text to the div element, the scroll-bar also goes to the bottom automatically?



Here's my div element:



<div class='panel-Body scroll' id='messageBody'></div>


And CSS class



.scroll {
height: 450px;
overflow: scroll;
}


What i need is, initially the position of the scroll-bar should be bottom.



Also when i clicked a send message, I'm adding the message to the div elements 'messageBody'. On that time the the scroll-bar should be down again.



This is the current style of my scroll-bar
enter



And I want it to be always
enter



Thanks in advance.


More From » jquery

 Answers
42
var messageBody = document.querySelector('#messageBody');
messageBody.scrollTop = messageBody.scrollHeight - messageBody.clientHeight;

[#59850] Tuesday, November 29, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
pariss

Total Points: 255
Total Questions: 99
Total Answers: 117

Location: Hungary
Member since Wed, Nov 9, 2022
2 Years ago
;