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 GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
labels |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.