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