1. .width()
console.log($("#box").width()); // Get width
$("#box").width(300); // Set width to 300px
2. .height()
console.log($("#box").height()); // Get height
$("#box").height(200); // Set height to 200px
3. .innerWidth()
console.log($("#box").innerWidth());
4. .outerHeight([includeMargin])
-
Gets the height including content, padding, and border.
-
If you pass true, it also includes margin.
console.log($("#box").outerHeight()); // Content + padding + border
console.log($("#box").outerHeight(true)); // Content + padding + border + margin
Illustration of Box Model in jQuery Dimensions
Margin (optional, only with true in outerHeight/outerWidth)
┌───────────────────────────┐
│ Border │
│ ┌───────────────────┐ │
│ │ Padding │ │
│ │ ┌───────────┐ │ │
│ │ │ Content │ │ │
│ │ └───────────┘ │ │
│ └───────────────────┘ │
└───────────────────────────┘
Quick Summary Table
| Method |
Includes |
.width() / .height() |
Content only |
.innerWidth() |
Content + Padding |
.outerHeight() |
Content + Padding + Border |
.outerHeight(true) |
Content + Padding + Border + Margin |