Detailed description of Jquery.outerwidth () function specific usage _jquery

Source: Internet
Author: User

Here's a demo of the Outerwidth () function through the jquery instance code,

The Outerwidth () function is used to set or return the outer width of the current matching element. The outer width defaults to include the element's inner margin (padding), Border (border), but does not include the width of the outer margin (margin) portion. You can also specify that the parameter is true to include the width of the outer margin (margin) portion. The following figure:

If you want to get the width of other situations, use width () and innerwidth (), and you can click here to see the difference between the three. This function belongs to the jquery object (instance) and is still valid for elements that are not visible. Syntax jquery 1.2.6 adds this function. Jqueryobject.outerwidth ([Includemargin]) Note: If the current jquery object matches more than one element, only the outer width of the first matching element is returned. Parameter parameter description includemargin Optional/boolean type Indicates whether the width of the outer margin portion is included, and the default is False. The return value of the Outerwidth () function returns the number type, returning the outer width of the first matching element. If the current jquery object matches more than one element, the Outerwidth () function takes only the first matching element when the outer width is returned. If there are no matching elements, NULL is returned. Outerwidth () is not available for Windows and document, please use width () instead. Example & description Use the following HTML code as an example:

Copy Code code 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 is used to demonstrate the specific use of the Outerwidth () function:

var $n 1 = $ ("#n1"); 
var $n 2 = $ ("#n2"); 
Outerwidth () = width (MB) + padding (10*2) + border (1*2) = 122 Document.writeln 
($n 1.outerWidth ());//122 
Docu Ment.writeln ($n 2.outerWidth ()); 150 


If multiple elements are matched, only the outerwidth of the first element is returned

Document.writeln ($divs. Outerwidth ()); 122 
//outerwidth (true) = width (MB) + padding (10*2) + border (1*2) + margin (5*2) = 132 

The above details the Jquery.outerwidth () function, I hope you can enjoy.

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.