Home >Web Front-end >CSS Tutorial >How to Get a Div's Height Using Plain JavaScript?
Question:
How can I obtain the height of a div element using only plain JavaScript, without relying on libraries like jQuery?
Answer:
To determine the height of a div element without using jQuery, you can employ the following methods:
var clientHeight = document.getElementById('myDiv').clientHeight;
This approach considers only the inner height of the div, including any padding applied.
Alternatively, you can use:
var offsetHeight = document.getElementById('myDiv').offsetHeight;
This method returns the height of the div, including its padding, borders, and scrollbar (if present).
Therefore, depending on your specific requirements, you can choose between clientHeight for inner height or offsetHeight for the total height of the div element.
The above is the detailed content of How to Get a Div's Height Using Plain JavaScript?. For more information, please follow other related articles on the PHP Chinese website!