To get div height with plain JavaScript, we use the clientHeight
or offsetHeight
property.
For instance, we write
const clientHeight = document.getElementById("myDiv").clientHeight;
const offsetHeight = document.getElementById("myDiv").offsetHeight;
to select the element with getElementById
.
And then we get the clientHeight
or the offsetHeight
to get the div’s height.
clientHeight
includes padding.
offsetHeight
includes padding, scrollBar and borders.