PASSWORD RESET

Your destination for complete Tech news

How to get the size of the screen in jquery?

271 0
< 1 min read

To get the size of the screen (the width and height) using jQuery, you can use the width and height functions. These functions return the width and height of the viewport, which is the area of the browser window that is visible to the user.

Here is an example of how you might use these functions to get the width and height of the screen and store them in variables:

var screenWidth = $(window).width();
var screenHeight = $(window).height();

You can also use the innerWidth and innerHeight functions to get the width and height of the viewport, including the scrollbars (if present).

var screenWidth = $(window).innerWidth();
var screenHeight = $(window).innerHeight();

If you want to get the width and height of the entire document (including any elements that extend beyond the viewport), you can use the document object instead of the window object.

var documentWidth = $(document).width();
var documentHeight = $(document).height();

Keep in mind that the width and height values returned by these functions are in pixels. If you want to get the size of the screen in other units, you will need to convert the values using a suitable conversion factor.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.