Query - Dimensions API reference for Query methods related to element dimensions maximize-2 API Reference
Categories

Query - Dimensions

Get and set element dimensions, scroll positions, and natural sizes.

Size

width

$('selector').width()
$('selector').width(value)

Gets or sets the width of elements.

Parameters

NameTypeDescription
valuenumber/stringThe width to set for the element(s)

Returns

Width in pixels.

Example

height

$('selector').height()
$('selector').height(value)

Gets or sets the height of elements.

Parameters

NameTypeDescription
valuenumber/stringThe height to set for the element(s)

Returns

Height in pixels.

Example

Scroll

scrollTop

$('selector').scrollTop()
$('selector').scrollTop(value)

Gets or sets the vertical scroll position of elements.

Parameters

NameTypeDescription
valuenumberThe vertical scroll position to set in pixels

Returns

Vertical scroll position in pixels.

Example

scrollLeft

$('selector').scrollLeft()
$('selector').scrollLeft(value)

Gets or sets the horizontal scroll position of elements.

Parameters

NameTypeDescription
valuenumberThe horizontal scroll position to set in pixels

Returns

Horizontal scroll position in pixels.

Example

Natural Size

naturalWidth

$('selector').naturalWidth()

Gets the natural width of an element, including images and other HTML elements.

Performance Note Creates an off-screen clone to measure dimensions. Can cause reflow - use sparingly in performance-critical code.

Returns

Natural width in pixels.

Example

naturalHeight

$('selector').naturalHeight()

Gets the natural height of an element, including images and other HTML elements.

Returns

Natural height in pixels.

Example

Comprehensive

dimensions

$('selector').dimensions()

Gets comprehensive dimension information for elements.

Returns

Object containing position, size, and box model data:

PropertyDescription
top, left, right, bottomViewport position
pageTop, pageLeftDocument position
width, heightContent dimensions
innerWidth, innerHeightContent + padding
outerWidth, outerHeightContent + padding + border
marginWidth, marginHeightFull box including margin
scrollTop, scrollLeftScroll position
scrollHeight, scrollWidthScrollable dimensions
boxBox model details (padding, border, margin)
boundsDOMRect bounding box

Example

Previous
CSS
Next
Display & Visibility