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.

読み取り専用のプロパティで、この CSS 宣言ブロックにあるスタイル宣言の数を整数で表します。

このインスタンスの親に明示的に設定されているスタイルの数を示す整数です。

次の例は、以下の HTML 要素に明示的に設定されたスタイルの数を取得します。

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

JavaScript コード:

js
const myDiv = document.getElementById("div1");
const divStyle = myDiv.style;
const len = divStyle.length; // 6

仕様書

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

ブラウザーの互換性

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
length

Legend

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

Full support
Full support