Describes in detail the usage of the jQuery. outerWidth () function, jqueryouterwidth

Source: Internet
Author: User

Describes in detail the usage of the jQuery. outerWidth () function, jqueryouterwidth

The following uses the jQuery instance code to demonstrate the outerWidth () function,

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:

Copy codeThe Code is as follows:
<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() ); // 122 document.writeln( $n2.outerWidth() ); // 150 var $divs = $("div"); 


// If multiple elements are matched, only the outerWidth of the first element is returned.

document.writeln( $divs.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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.