Introduction to jQuery
JQuery Syntax
JQuery Effects
JQuery HTML
JQuery Traversing
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 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 |
.width()
→ Get or set the width of an element..height()
→ Get or set the height of an elementBoth exclude padding, border, and margin.
The following example returns the width and height of a specified element:
Try it yourself
**.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:
Try it yourself
**.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:
Try it yourself
**.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.Try it yourself
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:
Try it yourself