CSSStyleDeclaration.getPropertyValue()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2015.

CSSStyleDeclaration.getPropertyValue() 接口返回一个 DOMString ,其中包含请求的 CSS 属性的值。

语法

var value = style.getPropertyValue(property);

参数

  • property 是一个 DOMString,是需要查询的 CSS 属性名称。

返回值

  • valueDOMString ,包含查找属性的值。若对应属性没有设置,则返回空字符串。

示例

下述示例使用一个 CSS 选择器规则查询对应的margin 属性的值:

js
var declaration = document.styleSheets[0].cssRules[0].style;
var value = declaration.getPropertyValue("margin"); // "1px 2px"

规范

Specification
CSS Object Model (CSSOM)
# dom-cssstyledeclaration-getpropertyvalue

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
getPropertyValue

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support