How to get the Screen Width in Javascript
Javascript gives a few options to determine the screen width.
When we say screen
, we mean the browser window’s width itself.
Option 1 – Using Native Javascript
Using native Javascript objects, we can find the innerWidth and innerHeight:
The window object also allows for:
We can write some code to tell us the width and height with fallbacks:
Option 2 – Get Width using jQuery
|
|
You can use this as follows: