1. 개발자를 위한 웹 기술
  2. Web API
  3. HTMLInputElement
  4. labels

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

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 ⁨2018년 10월⁩.

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

브라우저 호환성

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.

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