CSSOM
The primitiveType read-only property of the
CSSPrimitiveValue interface represents the type of a CSS value.
[!NOTE] This property was part of an attempt to create a typed CSS Object Model. This attempt has been abandoned, and most browsers do not implement it.
To achieve your purpose, you can use:
- the untyped CSS Object Model, widely supported, or
- the modern CSS Typed Object Model API, less supported and considered experimental.
Value
An unsigned short representing the type of the value. Possible values are:
<table class="no-markdown"> <thead> <tr> <th>Constant</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code>CSS_ATTR</code></td> <td> The value is an attr function. The value can be obtained by using the <code>getStringValue()</code> method. </td> </tr> <tr> <td><code>CSS_CM</code></td> <td> The value is a <length> in centimeters. The value can be obtained by using the <code>getFloatValue()</code> method. </td> </tr> <tr> <td><code>CSS_COUNTER</code></td> <td> The value is a <a href="/en-US/docs/Web/CSS/Guides/Counter_styles/Using_counters" >counter or counters</a > function. The value can be obtained by using the <code>getCounterValue()</code> method. </td> </tr> <tr> <td><code>CSS_DEG</code></td> <td> The value is an <angle> in degrees. The value can be obtained by using the <code>getFloatValue()</code> method. </td> </tr> <tr> <td><code>CSS_DIMENSION</code></td> <td> The value is a <number> with an unknown dimension. The value can be obtained by using the <code>getFloatValue()</code> method. </td> </tr> <tr> <td><code>CSS_EMS</code></td> <td> The value is a <length> in em units. The value can be obtained by using the <code>getFloatValue()</code> method. </td> </tr> <tr> <td><code>CSS_EXS</code></td> <td> The value is a <length> in ex units. The value can be obtained by using the <code>getFloatValue()</code> method. </td> </tr> <tr> <td><code>CSS_GRAD</code></td> <td> The value is an <angle> in grads. The value can be obtained by using the <code>getFloatValue()</code> method. </td> </tr> <tr> <td><code>CSS_HZ</code></td> <td> The value is a <frequency> in Hertz. The value can be obtained by using the getFloatValue method. </td> </tr> <tr> <td><code>CSS_IDENT</code></td> <td> The value is an identifier. The value can be obtained by using the <code>getStringValue()</code> method. </td> </tr> <tr> <td><code>CSS_IN</code></td> <td> The value is a <length> in inches. The value can be obtained by using the <code>getFloatValue()</code> method. </td> </tr> <tr> <td><code>CSS_KHZ</code></td> <td> The value is a <frequency> in Kilohertz. The value can be obtained by using the <code>getFloatValue()</code> method. </td> </tr> <tr> <td><code>CSS_MM</code></td> <td> The value is a <length> in millimeters. The value can be obtained by using the <code>getFloatValue()</code> method. </td> </tr> <tr> <td><code>CSS_MS</code></td> <td> The value is a <time> in milliseconds. The value can be obtained by using the <code>getFloatValue()</code> method. </td> </tr> <tr> <td><code>CSS_NUMBER</code></td> <td> The value is a simple <number>. The value can be obtained by using the <code>getFloatValue()</code> method. </td> </tr> <tr> <td><code>CSS_PC</code></td> <td> The value is a <length> in picas. The value can be obtained by using the <code>getFloatValue()</code> method. </td> </tr> <tr> <td><code>CSS_PERCENTAGE</code></td> <td> The value is a <percentage>. The value can be obtained by using the <code>getFloatValue()</code> method. </td> </tr> <tr> <td><code>CSS_PT</code></td> <td> The value is a <length> in points. The value can be obtained by using the <code>getFloatValue()</code> method. </td> </tr> <tr> <td><code>CSS_PX</code></td> <td> The value is a <length> in pixels. The value can be obtained by using the <code>getFloatValue()</code> method. </td> </tr> <tr> <td><code>CSS_RAD</code></td> <td> The value is an <angle> in radians. The value can be obtained by using the <code>getFloatValue()</code> method. </td> </tr> <tr> <td><code>CSS_RECT</code></td> <td> The value is a shape function. The value can be obtained by using the <code>getRectValue()</code> method. </td> </tr> <tr> <td><code>CSS_RGBCOLOR</code></td> <td> The value is an <color>. The value can be obtained by using the <code>getRGBColorValue()</code> method. </td> </tr> <tr> <td><code>CSS_S</code></td> <td> The value is a <time> in seconds. The value can be obtained by using the <code>getFloatValue()</code> method. </td> </tr> <tr> <td><code>CSS_STRING</code></td> <td> The value is a <string>. The value can be obtained by using the <code>getStringValue()</code> method. </td> </tr> <tr> <td><code>CSS_UNKNOWN</code></td> <td> The value is not a recognized CSS2 value. The value can only be obtained by using the CSSValue.cssText attribute. </td> </tr> <tr> <td><code>CSS_URI</code></td> <td> The value is a url_value. The value can be obtained by using the <code>getStringValue()</code> method. </td> </tr> </tbody> </table>
Examples
const cs = window.getComputedStyle(document.body);
const cssValue = cs.getPropertyCSSValue("color");
console.log(cssValue.primitiveType);
Specifications
This feature was originally defined in the DOM Style Level 2 specification, but has been dropped from any standardization effort since then.
It has been superseded by a modern, but incompatible, CSS Typed Object Model API that is now on the standard track.
Browser compatibility
See also
- CSSStyleDeclaration.getPropertyCSSValue()
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
