1. 開発者向けのウェブ技術
  2. Web API
  3. HTMLButtonElement
  4. HTMLButtonElement: labels プロパティ

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

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

ブラウザーの互換性

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.

AltStyle によって変換されたページ (->オリジナル) /