The read-only property returns an integer that represents the number of style declarations in this CSS declaration block.

句法

var num = styles.length;
					

An integer that provides the number of styles explictly set on the parent of the instance.

范例

The following gets the number of explicitly set styles on the following HTML element:

<div id="div1" style="margin: 0 10px; background-color: #CA1; font-family: monospace"></div>
					

JavaScript code:

var myDiv = document.getElementById('div1'); var divStyle = myDiv.style; var len = divStyle.length; // 6
					

规范

规范 状态 注释
CSS Object Model (CSSOM)
The definition of 'CSSStyleDeclaration.length' in that specification.
工作草案
Document Object Model (DOM) Level 2 Style Specification
The definition of 'CSSStyleDeclaration' in that specification.
过时

浏览器兼容性

The compatibility table in 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. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
length Chrome 1 Edge 12 Firefox 1 IE Yes Opera Yes Safari 6 WebView Android 4.4 Chrome Android 18 Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android 1.0

图例

完整支持

完整支持

元数据

  • 最后修改: