JQuery. outerWidth () function details, jqueryouterwidth
The outerWidth () function is used to set or return the outer width of the currently matched element. By default, the outer width includes the element's padding (padding) and border (border), but does not include the width of the outer margin (margin. You can also specify the parameter to true to include the width of the margin (margin. For example:
If you want to obtain the width of other cases, use width () and innerWidth (). You can click here to view the differences between the three. This function is a jQuery object (instance) and is still valid for invisible elements. This function is added in the syntax jQuery 1.2.6. JQueryObject. outerWidth ([includeMargin]) Note: if the current jQuery object matches multiple elements, only the outer width of the first matched element is returned. Parameter description includeMargin optional/Boolean type indicates whether the width of the margin is included. The default value is false. The Return Value of the outerWidth () function is of the Number type, and the outer width of the First Matching Element is returned. If the current jQuery object matches multiple elements and returns the outer width, the outerWidth () function takes the first matching element as the standard. If no matching element exists, null is returned. OuterWidth () is not applicable to Windows and document. Use width () instead. Example:
<div id="n1" style="margin:5px; padding: 10px; width:100px; height: 100px; border: 1px solid #000;"></div><div id="n2" style="width:150px; height: 100px; background: #999;"></div>
The following jQuery Sample Code demonstrates the usage of the outerWidth () function:
Var $ n1 = $ ("# n1"); var $ n2 = $ ("# n2"); // outerWidth () = width (100) + padding (10*2) + border (1*2) = 122 document. writeln ($ n1.outerWidth (); // 122document. writeln ($ n2.outerWidth (); // 150var $ divs = $ ("div"); // if multiple elements are matched, only the outerWidthdocument of the first element is returned. writeln ($ divs. outerWidth (); // 122 // outerWidth (true) = width (100) + padding (10*2) + border (1*2) + margin (5*2) = 132 document. writeln ($ n1.outerWidth (true); // 132document. writeln ($ n2.outerWidth (true); // 150
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.