HTMLCollection namedItem() 메서드
예시
ID가 "myElement"인 P 요소의 콘텐츠를 가져옵니다.
function myFunction() {
var x = document.getElementsByTagName("P").namedItem("myElement");
alert(x.innerHTML);
}
정의 및 사용
이 namedItem()
메서드는 HTMLCollection에서 지정된 ID 또는 이름을 가진 요소를 반환합니다.
속기 방법도 사용할 수 있으며 동일한 결과를 생성합니다.
var x = document.getElementsByTagName("P")["myElement"];
브라우저 지원
Method | |||||
---|---|---|---|---|---|
namedItem() | Yes | Yes | Yes | Yes | Yes |
통사론
HTMLCollection.namedItem(name)
또는:
HTMLCollection[name]
매개변수 값
Parameter | Description |
---|---|
name | Required. The value of the id attribute, or name attribute, of the element you want to return. |
반환 값
지정된 ID 또는 이름을 가진 의 요소를 나타내는 Element 개체 입니다 .
요소가 존재하지 않으면 null 을 반환 합니다.
관련 페이지
HTMLCollection: item() 메서드
HTMLCollection: 속성 길이