HTMLButtonElement: labels プロパティ
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2018年10月.
HTMLButtonElement.labels
は読み取り専用プロパティで、この
<button>
要素に関連付けられた <label>
要素を NodeList
で返します。
値
NodeList
で、この <button>
要素に関連付けられた <label>
要素を返します。
例
>HTML
html
<label id="label1" for="test">Label 1</label>
<button id="test">Button</button>
<label id="label2" for="test">Label 2</label>
JavaScript
js
window.addEventListener("DOMContentLoaded", () => {
const button = document.getElementById("test");
for (const label of button.labels) {
console.log(label.textContent); // "Label 1" and "Label 2"
}
});
結果
仕様書
Specification |
---|
HTML> # dom-lfe-labels-dev> |
ブラウザーの互換性
Loading…