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()".
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:
When I reduce the width of the browser's visual window:
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!