Skip to content

@technobuddha > react-hooks > DOM > Analysis

Function: measure()

ts
function measure(element: HTMLElement): Size;

Defined in: measure.ts:21

Measures the size of an HTMLElement.

Parameters

ParameterTypeDescription
elementHTMLElementThe HTMLElement to measure.

Returns

Size

Properties: width, height, scrollbarWidth, scrollbarHeight.

Example

typescript
const el = document.getElementById('myDiv');
if (el) {
  const size = measure(el);
  // size: { width: 1024, height: 768, scrollbarWidth: 16, scrollbarHeight: 16 }
}