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 属性名称。
返回值
value
是DOMString
,包含查找属性的值。若对应属性没有设置,则返回空字符串。
示例
下述示例使用一个 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 GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
getPropertyValue |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
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.