Categories
JavaScript Answers

How to get document height and width with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *