DOMTokenList.keys()
keys() は DOMTokenList インターフェイスのメソッドで、このオブジェクトに含まれるすべてのキーを処理することができるイテレーターを返します。キーの型は符号なし整数です。
構文
js
keys();
引数
なし
返値
イテレーターを返します。
例
次の例では、 <span> 要素に設定されたクラスのリストを DOMTokenList として受け取るために、 Element.classList を使用しています。 keys() を使用してキーを含むイテレーターを取得してから、 for...of ループを使用してそれぞれを反復処理し、それを <span> の Node.textContent に書き込みます。
最初に HTML です。
html
<span class="a b c"></span>
そして JavaScript です。
js
const span = document.querySelector("span");
const classes = span.classList;
const iterator = classes.keys();
for(let value of iterator) {
span.textContent += `(${value}) `;
}
出力結果は以下のようになります。
仕様書
No specification found
No specification data found for api.DOMTokenList.keys.
Check for problems with this page or contribute a missing spec_url to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.
ブラウザーの互換性
BCD tables only load in the browser