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 July 2015.
値
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 Standard # dom-lfe-labels-dev |
ブラウザーの互換性
BCD tables only load in the browser