Sometimes, we want to get div height with plain JavaScript.
In this article, we’ll look at how to get div height with plain JavaScript.
How to get div height with plain JavaScript?
To get div height with plain JavaScript, we use the clientHeight
or offsetHeight
properties.
For instance, we write
const clientHeight = document.getElementById("myDiv").clientHeight;
const offsetHeight = document.getElementById("myDiv").offsetHeight;
to get the div with getElementById
.
Then we get the div’s height with the clientHeight
and offsetHeight
properties.
clientHeight
includes the padding with the height.
And offsetHeight
includes padding, scrollbar and border heights.
Conclusion
To get div height with plain JavaScript, we use the clientHeight
or offsetHeight
properties.