Home  >  Article  >  Web Front-end  >  How to find browser width with jquery

How to find browser width with jquery

WBOY
WBOYOriginal
2021-12-13 15:46:222103browse

Jquery method to find the width of the browser: 1. Use the "$()" method to obtain the browser window object; 2. Use the width() method to find the width of the specified browser object. This method is used to return Or set the width of the matching element, the syntax is "$(window).width()".

How to find browser width with jquery

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

How to find the width of the browser with jquery

We can find the width of the browser through the width() method. The width() method returns or Sets the width of the matching element.

To match the browser, we can use the $(window) statement to get the current window.

The example is as follows:

<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
    $(document).ready(function()  {
        alert($(window).width()); 
    });
</script>
</head>
<body>
</body>
</html>

After running the code, the output result is:

How to find browser width with jquery

When I reduce the width of the browser's visual window:

How to find browser width with jquery

Recommended related video tutorials: jQuery video tutorial

The above is the detailed content of How to find browser width with jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn