Sometimes, we want to get document height and width with JavaScript.
In this article, we’ll look at how to get document height and width with JavaScript.
How to get document height and width with JavaScript?
To get document height and width with JavaScript, we can use the clientWidth and clientHeight properties.
For instance, we write
const height = document.body.clientHeight;
const width = document.body.clientWidth;
to get the width and height of the body element with clientWidth and clientHeight respectively.
We use document.body to get the body element.
Conclusion
To get document height and width with JavaScript, we can use the clientWidth and clientHeight properties.