HTMLInputElement: labels property

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.

HTMLInputElement.labels 읽기 전용 속성은 요소가 숨겨져 있지 않은 경우 <input> 요소와 연관된 <label> 요소의 NodeList를 반환합니다. 요소의 타입이 hidden인 경우, 속성은 null을 반환합니다.

<input> 요소와 연관된 <label> 요소를 포함하는 NodeList입니다.

예제

HTML

html
<label id="label1" for="test">Label 1</label>
<input id="test" />
<label id="label2" for="test">Label 2</label>

JavaScript

js
window.addEventListener("DOMContentLoaded", () => {
  const input = document.getElementById("test");
  for (const label of input.labels) {
    console.log(label.textContent); // "Label 1" 과 "Label 2"
  }
});

명세서

Specification
HTML
# dom-lfe-labels-dev

브라우저 호환성

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
labels

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support