Home > Web Front-end > JS Tutorial > body text

Detailed introduction to the specific usage of jQuery.outerWidth() function_jquery

WBOY
Release: 2016-05-16 15:49:33
Original
1004 people have browsed it

Let’s demonstrate the outerWidth() function through jQuery example code,

The outerWidth() function is used to set or return the outer width of the current matching element. By default, the outer width includes the padding and border of the element, but does not include the width of the margin part. You can also specify the parameter as true to include the width of the margin portion. As shown below:

If you want to get the width of other situations, please use width() and innerWidth(). You can click here to see the difference between the three. This function belongs to a jQuery object (instance) and still works on invisible elements. Syntax jQuery 1.2.6 Added this function. jQueryObject.outerWidth( [ includeMargin ] ) Note: If the current jQuery object matches multiple elements, only the outer width of the first matching element is returned. Parameter Parameter Description includeMargin Optional/Boolean type indicates whether to include the width of the margin part. The default is false. Return value The return value of the outerWidth() function is of type Number, returning the outer width of the first matching element. If the current jQuery object matches multiple elements, when returning the outer width, the outerWidth() function only uses 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. Examples & Instructions Take the following HTML code as an example:

Copy code The code is as follows:



The following jQuery sample code is used to demonstrate the specific 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"); 
Copy after login


// 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 
Copy after login

The above content introduces the jQuery.outerWidth() function in detail, I hope you will like it.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template