HTML DOM 문서 getElementsByName()
예시
이름이 "fname"인 모든 요소를 가져옵니다.
let collection = document.getElementsByName("fname");
아래에서 더 많은 "직접 사용해 보기" 예를 살펴보세요.
정의 및 사용
이 getElementsByName()
메서드는 지정된 이름을 가진 요소 컬렉션을 반환합니다.
이 getElementsByName()
메서드는 HTMLCollection 을 반환합니다 .
또한보십시오:
통사론
document.getElementsByName(name)
매개변수
Parameter | Description |
name | Required. The name value of the elements. |
반환 값
유형 | 설명 |
물체 | HTMLCollection 개체 . 지정된 이름을 가진 요소의 컬렉션입니다. 요소는 문서에 나타나는 대로 정렬됩니다. |
더 많은 예
name="animal"인 요소 수:
let num = document.getElementsByName("animal").length;
이름이 "animal"이고 type="checkbox"인 모든 <input> 요소를 확인합니다.
const collection = document.getElementsByName("animal");
for (let i = 0; i < collection.length; i++) {
if (collection[i].type == "checkbox") {
collection[i].checked = true;
}
}
브라우저 지원
document.getElementsByName()
DOM 레벨 1(1998) 기능입니다.
모든 브라우저에서 완벽하게 지원됩니다.
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |