DOMTokenList: length プロパティ
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
length
は DOMTokenList
インターフェイスの読み取り専用プロパティで、オブジェクト内に格納されたオブジェクトの個数を整数で表します。
値
正の整数、またはリストが空であれ 0
です。
例
次の例は、 <span>
要素に設定されたクラスのリストを Element.classList
を使用して DOMTokenList
として取得し、そのリストの長さを <span>
の Node.textContent
の中に書き込みます。
最初に HTML です。
html
<span class="a b c"></span>
そして JavaScript です。
js
const span = document.querySelector("span");
const classes = span.classList;
const length = classes.length;
span.textContent = `classList length = ${length}`;
出力結果は以下のようになります。
仕様書
Specification |
---|
DOM # ref-for-dom-domtokenlist-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.