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
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.
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.
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.
Get the scrollHeight
property from the underlying DOM element:
$("#chat_content").scrollTop($("#chat_content").get(0).scrollHeight);
try $("#chat_content").scrollTop($("#chat_content").get(0).scrollHeight);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With