In order to get screen width and height of your browser window using jQuery check out the below code. As you resize your browser window the values of the width and height of the frame are displayed.
This code can be quite handy when your testing your responsive design of your website. You can view this page on various devices to get the height and width.
Code Example:<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="../js/jquery-1.10.2.min.js" >
</script>
<style>
#display {
width: auto;
height:22px;
background-color: #ccc;
color: #222;
margin-left: 5px;
font-size:20px;
text-align: center;
}
</style>
</head>
<body>
<script>
$("#display").html("<b>Width</b> : " +
$(window).width() + ",<b>Height : </b>" +
$(window).height());
$(window).resize(function() {
$("#display\").html("<b>Width</b> : " +
$(window).width() + ",<b>Height : </b>" +
$(window).height());
});
</script>
<div id="display"></div>
</body>
</html>
You can see the below gif file - you can see that as we resize the browser window, we get the correct width and height size in pixels.

⛏️ Note: There is an easier way to do this using the Chrome browser Inspect option, Right Click on any web page and click on Inspect, click on "Toggle Device Toolbar" and select the responsive option, drag the width and height to know how your page renders and what the page dimensions are.
Have Questions? Post them here!
- How to check if an element is hidden using jQuery code?
- Disable jQuery button after being click
- Make div element draggable using jQuery
- Get Browser Screen Width and Height dynamically using jQuery
- jQuery : Move to top of the page
- [jQuery] Uncaught ReferenceError: $ is not defined at index.html:5
- Redirect page using jQuery
- How to activate and use Microsoft Teams Together mode - Microsoft
- List of 32 CSS cursors web developers must know about - CSS
- List of jars required for Struts2 project - Java
- How to uninstall pip Python packages - Python
- Run Java Code Every Second - Java
- How to copy file name and path to clipboard in Notepad++ - NotepadPlusPlus
- [Solved] SharePoint Search Internal server error exception - SharePoint
- hibernate.cfg.xml Configuration and Mapping xml Example - Java