Back to Content

CSSNumericValue: parse() static method

files/en-us/web/api/cssnumericvalue/parse_static/index.md

latest734 B
Original Source

{{APIRef("CSS Typed OM")}}

The parse() static method of the {{domxref("CSSNumericValue")}} interface converts a value string into an object whose members are value and the units.

Syntax

js-nolint
CSSNumericValue.parse(cssText)

Parameters

  • cssText
    • : a string containing numeric and unit parts.

Return value

A {{domxref('CSSNumericValue')}}.

Exceptions

  • SyntaxError {{domxref("DOMException")}}
    • : TBD

Examples

The following returns a {{domxref('CSSUnitValue')}} object with a unit property equal to "px" and a value property equal to 42.

js
let numValue = CSSNumericValue.parse("42.0px");

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}