Reputation: 867
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
Upvotes: 3
Views: 2424
Reputation: 516
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.
Upvotes: 3
Reputation: 1455
.Height
if you need height of div excluding margin/padding/border.
.innerHeight
if you need height of div with padding but without border + margin
.outerHeight
if you need height of div including padding and border
.outerHeight(true)
if you need height of div including border + margin + padding
Upvotes: 1