Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

offsetHeight vs. clientHeight

I am trying to get the height of a div using javascript. I have seen this question a lot on stackoverflow and seen both answers. Some say clientHeight and some say offsetHeight. For my project, I have a div with content inside that does not have a pre-set css height. I want to get the height of it with javascript. Which is better to use? and please NO JQUERY. Thanks

like image 656
krummens Avatar asked Dec 29 '25 21:12

krummens


1 Answers

The difference between the two is what is included in the value you get.

Specifically, clientHeight will give you the height of the visible height of the div including the padding but excluding the scrollBar, border and margin whereas offsetHeight will give you the visible height of the div including scrollBar, padding and the border but excluding the margin.

like image 149
Jasvir Avatar answered Jan 01 '26 10:01

Jasvir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!