avinash majhi avinash majhi - 3 months ago 17
CSS Question

How to get inner HTML content height

I want to get inner html height by JavaScript. Suppose I have

<div>Content</div>


either if the div font size has increased or many divs nested inside the parent, how do I get the height of parent div?

edit: even if the nested div has border and padding too.

Answer

If it must be in vanilla JS...

var height = document.getElementById('content').clientHeight;

That will include any borders or scrollbars in the element. If you want JUST the inner HTML (excluding the padding), you may use offsetHeight instead.

Comments