.outerWidth()
methodThe .outerWidth()
method in jQuery is used to get/set the outer width (including padding, border and optionally margin) of the matched element.
.outerWidth()
method Syntax.outerWidth([includeMargin]) .outerWidth(value) .outerWidth(function)
Parameter | Type | Description |
---|---|---|
inlcudeMargin |
Boolean | whether to include the element's margin when computing, default false |
value |
String,Number | the outer width value to set |
funtion(index, oldWidth) |
Function | a function returning the outer width to set. index is the position of the element in the set.(based on 0) oldWidth is the old outer width. |
.outerWidth()
Get the current computed outer width(including padding,border and optionally margin) of the first matched element.(If the element is not visible, the width would be 0 )
Get the outer width of the first paragraph
$("p").outerWidth(); $("p").outerWidth(true); // including the margin
.outerWidth(value)
Set the outer width of every matched elements.
Set the outerWidth of each p to 300px
$("p").outerWidth(300);
.outerWidth(function)
Set the outerWidth of the element to 20px wider than the previous.
$("p").outerWidth(function(index,oldValue){ return 20*index + oldValue; });