Accurately measuring element size is essential for layout calculations, drag-and-drop, and responsive components. jQuery provides a clean set of dimension methods that abstract the confusing native properties like offsetWidth, clientWidth, and scrollWidth.
Width and Height Methods
.width() and .height() return the content area dimensions excluding padding, border, and margin. .innerWidth() / .innerHeight() include padding, and .outerWidth() / .outerHeight() also include the border. Pass true to the outer methods to include the margin as well.
Setting Dimensions
All these methods double as setters when you pass a value. You can pass a number (treated as pixels) or a string with a unit like '50%'.
.width()— content width only.innerWidth()— content + padding.outerWidth()— content + padding + border.outerWidth(true)— all of the above + margin
To get the full document or viewport dimensions use $(document).height() or $(window).width() respectively.