Jquery.outerwidth () function explanation

Source: Internet
Author: User

The Outerwidth () function is used to set or return the outer width of the currently matched element. The outer width default includes the element's padding (padding), Border (border), but not the width of the margin section. You can also specify a parameter of true to include the width of the margin section. Such as:


If you want to get the width of other cases, please use width () and innerwidth (), you can click here to see the difference between the three. The 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 matched element is returned. Parameter parameter description includemargin Optional/boolean type Indicates whether the width of the margin section is included, false by default. Return value 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, and the outer width is returned, the Outerwidth () function only takes precedence over the first matching element. If there are no matching elements, NULL is returned. Outerwidth () is not available for window and document, please use width () instead. Example & description Take this HTML code as an 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 specific use of the Outerwidth () function:

var $n 1 = $ ("#n1"), var $n 2 = $ ("#n2"),//outerwidth () = width (+) + padding (10*2) + border (1*2) = 122 Document.writeln ($ N1.outerwidth ()); 122document.writeln ($n 2.outerWidth ()); 150var $divs = $ ("div");//If multiple elements are matched, only the outerwidthdocument.writeln of the first element ($divs. Outerwidth ()) is returned; 122//outerwidth (true) = width (+) + padding (10*2) + border (1*2) + margin (5*2) = Document.writeln ($n 1.outerWidth (t Rue)); 132document.writeln ($n 2.outerWidth (true)); 150


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Jquery.outerwidth () function explanation

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.