I am in such a situation that I have to set height of a div depends on the amount of content in it, I can't give min-height
in it. I know we can calculate height of div by :
$("#divid").height();
So is there any way we can calculate height of a div without having height parameter in it and give height to that div depends on the amount of content in it.
I hope I explained it clearly.
Thanks
Your wording is a bit confusing, but I think you are asking how to calculate the size of the content inside a div even if the div has a different height applied. For that you can use the element's scrollHeight.
$('#divid')[0].scrollHeight
If you just want to know how to calculate the height of an element even though it has no attribute/style for height, you can just use what you have written in the question. .height()
computes the height of the element directly from the browser rendered values, not from the attributes specifically.
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