CSSNumericValue: to() method
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
The to()
method of the
CSSNumericValue
interface converts a numeric value from one unit to
another.
Syntax
js
to(unit)
Parameters
unit
-
The unit to which you want to convert.
Return value
A CSSMathSum
.
Exceptions
SyntaxError
DOMException
-
Thrown if an invalid type was passed to the method.
TypeError
-
Thrown if the passed values cannot be summed.
Examples
js
// Prints "0.608542cm"
console.log(CSS.px("23").to("cm").toString());
Specifications
Specification |
---|
CSS Typed OM Level 1 # dom-cssnumericvalue-to |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
to |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- See implementation notes.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.