This article uses the jQuery sample code to demonstrate the specific usage of the outerWidth () function. The introduction is very detailed. If you need it, you can refer to the following example to demonstrate the outerWidth () function through the jQuery instance code,
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:
The Code is as follows:
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() ); // 122 document.writeln( $n2.outerWidth() ); // 150 var $ps = $("p");
// If multiple elements are matched, only the outerWidth of the first element is returned.
document.writeln( $ps.outerWidth() ); // 122 //outerWidth(true) = width(100) + padding(10*2) + border(1*2) + margin(5*2) = 132 document.writeln( $n1.outerWidth(true) ); // 132
The above content introduces the jQuery. outerWidth () function in detail, I hope you will like it.