Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get height for a div with overflow:auto;

i have a div with height:100px and overflow:auto the content is dynamic.

i want scroll the div in the bottom

i tried with

$("#chat_content").scrollTop($("#chat_content").height());

but if the content is bigger than 100px $("#chat_content").height() returns 100 and the div isn't scrolled on the bottom

how can i do?

thanks

like image 401
Luca Romagnoli Avatar asked Jul 13 '10 09:07

Luca Romagnoli


People also ask

How can we get dynamic height of div?

We use css property height: calc( 100% - div_height ); Here, Calc is a function. It uses mathematical expression by this property we can set the height content div area dynamically.

How do I change the overflow height in CSS?

In order for overflow to have an effect, the block-level container must have either a set height ( height or max-height ) or white-space set to nowrap . Setting one axis to visible (the default) while setting the other to a different value results in visible behaving as auto . The JavaScript Element.

How do I set auto height in HTML?

If height: auto; the element will automatically adjust its height to allow its content to be displayed correctly. If height is set to a numeric value (like pixels, (r)em, percentages) then if the content does not fit within the specified height, it will overflow.


2 Answers

Get the scrollHeight property from the underlying DOM element:

$("#chat_content").scrollTop($("#chat_content").get(0).scrollHeight);
like image 184
Andy E Avatar answered Sep 21 '22 18:09

Andy E


try $("#chat_content").scrollTop($("#chat_content").get(0).scrollHeight);

like image 6
Roki Avatar answered Sep 18 '22 18:09

Roki