Advertisement
Google Ad Slot: content-top
jQuery Dimensions
In jQuery, dimensions refer to getting or setting an element's height, width, inner dimensions, and outer dimensions, with or without padding, border, and margin.
jQuery Dimension Methods
jQuery has several important methods for working with dimensions:
Method |
Description |
|---|---|
.width() |
Get/set the content width (no padding, border, margin) |
.height() |
Get/set the content height |
.innerWidth() |
Includes padding |
.innerHeight() |
Includes padding |
.outerWidth() |
Includes padding + border |
.outerHeight() |
Includes padding + border |
.outerWidth(true) |
Includes padding + border + margin |
.outerHeight(true) |
Includes padding + border + margin |
jQuery Dimensions
jQuery width() and height() Methods
.width()→ Get or set the width of an element..height()→ Get or set the height of an element
Both exclude padding, border, and margin.
The following example returns the width and height of a specified element:
jQuery innerWidth() and innerHeight() Methods
**.innerWidth()**→ Returns the width + padding of an element.**.innerHeight()**→ Returns the height + padding of an element.
The following example returns the inner-width/height of a specified element:
jQuery outerWidth() and outerHeight() Methods
**.outerWidth()**→ Gets the width of an element including padding and border.**.outerHeight()**→ Gets the height of an element including padding and border.
The following example returns the outer-width/height of a specified element:
**.outerWidth(true)**→ Gets the width of an element including padding, border and margin also.**.outerHeight(true)**→ Gets the height of an element including padding, border and margin also.
jQuery set width() and height() Methods
jQuery’s .width() and .height() methods to set the width and height of HTML elements easily.
The following example sets the width and height of a specified <div> element: