Element: children 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.

읽기 전용인 children 속성은 호출된 요소의 모든 자식 요소를 포함하는 동적인 HTMLCollection을 반환합니다.

Element.children은 요소 노드만을 포함합니다. 텍스트 및 주석 노드와 같이 요소가 아닌 노드를 포함한 모든 자식 노드를 가져오기 위해서는 Node.childNodes를 사용합니다.

HTMLCollectionnode의 자식인 DOM 요소의 동적이고 정렬된 컬렉션입니다. 컬렉션의 item() 메서드 혹은 JavaScript 배열 형식 표기법을 사용하여 컬렉션의 개별 자식 노드에 접근할 수 있습니다.

요소에 요소 자식이 없으면 childrenlength0인 빈 목록입니다.

예제

js
const myElement = document.getElementById("foo");
for (const child of myElement.children) {
  console.log(child.tagName);
}

명세서

Specification
DOM
# ref-for-dom-parentnode-children①

브라우저 호환성

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
children

Legend

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

Full support
Full support

같이 보기