CSSStyleDeclaration.length
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.
这是一个只读的属性,它返回一个指定元素声明过的样式个数
语法
var num = styles.length;
值
指定元素上明确声明过的样式属性个数。
示例
获取下面 HTML 元素明确设置过的属性个数:
html
<div
id="div1"
style="margin: 0 10px; background-color: #CA1; font-family: monospace"></div>
JavaScript 代码:
var myDiv = document.getElementById('div1'); var divStyle = myDiv.style; var len = divStyle.length; // 6
规范
Specification |
---|
CSS Object Model (CSSOM) # dom-cssstyledeclaration-length |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
length |
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.